Tag:regular expression

  • Using regular expression to judge prime code

    Time:2021-6-12

    Copy codeThe code is as follows: import re def is_prime(num): return not re.match(r”^1?$|^(11+?)\1+$”, ‘1’ * num) This regular expression actually represents all “1” strings of aggregate length (including the special case “1”). (11+?) Denotes all integers greater than or equal to 2, followed by the following 1 + denotes repeated more than once – isn’t […]

  • Replacing emoticon core code with regular expressions

    Time:2021-6-11

    Copy codeThe code is as follows: String a = “Wahaha [em: 5] aa8888 [em: 7];String r = “\\[em:(\\d+)\\]”; a = a.replaceAll(r, “$1.gif”); System.out.println(a); The result is: 5. Gifaa88887. Gif You can make the most of it.

  • Proficient in regular expressions in JavaScript

    Time:2021-6-8

    Regular expressions can:· test a pattern of a string. For example, you can test an input string to see if there is a phone number pattern or a credit card number pattern in the string. This is called data validationReplace the text. You can use a regular expression in the document to identify specific text, […]

  • PHP regular expression library (two sets)

    Time:2021-5-31

    There are two sets of regular expression function libraries in PHP, which have similar functions, but slightly different execution efficiencyOne is provided by PCRE (Perl compatible regular expression) library. Using “preg” Functions named for prefixes;One set is provided by POSIX (portable operating system interface of Unix) extension (PHP default). Use to “ereg” Functions named for […]

  • Regular expression advanced skills and examples

    Time:2021-5-30

    The original English text is from Smashing Magazine. Translated by stupid workers. Please indicate the source of the reprint. Regular expression,abbr. regex)Powerful, can be used to find the required information in a large string of characters. It uses the conventional character structure expression to function. Unfortunately, simple regular expressions are far from enough for some […]

  • Position matching of JS regular expression

    Time:2021-5-14

    http://regexpal.com/ The above website can be used to detect the regular expression syntax of JS online In addition to a few well-known fixed characters indicating position: ^ : Match the beginning of the string and, in multiline searches, the beginning of a line. $ : Match the end of the string and, in multiline searches, the end […]

  • Regexp property, method and application analysis of JavaScript regular expression

    Time:2021-5-13

    Use the explicit constructor of regexp with the syntax: new regexp (“pattern” [, “flags”]).The implicit constructor of regexp is used, and the plain text format is adopted: pattern / [flags].The pattern section is the regular expression pattern text to be used and is required. In the first way, the pattern part is in the form […]

  • JavaScript mobile phone number regular expression verification function

    Time:2021-5-12

    Copy codeThe code is as follows: function checkMobile(){     var sMobile = document.mobileform.mobile.value     if(!(/^1[3|4|5|8][0-9]\d{4,8}$/.test(sMobile))){          Alert (“not the complete 11 digit mobile phone number or the top seven digits of the correct mobile phone number”);        document.mobileform.mobile.focus();         return false;     } } The following is a simple analysis of the regular expression above by developer editor. With the increase […]

  • PHP regular expressions commonly used in the introduction and application example code

    Time:2021-5-9

    More comprehensive examples can be referred toCollection and collation of the most commonly used PHP regular expressionshttps://www.jb51.net/article/14049.htm PHP regular expression summaryhttps://www.jb51.net/article/19831.htm Several skills of using PHP regular expressionhttps://www.jb51.net/article/19832.htm The following content is commonly used in PHP regular, regular is a general syntax, you can download more comprehensive regular online, to provide learning!Functions: segmentation, matching, search, […]

  • Reverse pre search in regular expressions

    Time:2021-5-7

    In the past, most of the applications are forward pre search. In other words, there are specific content restrictions on the right side of the search content, such as the following example: Copy codeThe code is as follows: var str3 = ‘CPU: Intel Core2 5200; Memory: 2G;OS: Ubuntu 9.04’; var reg3 = /Memory\:\s+(.*(?=\;OS\:))/gim; str3.match(reg3); alert(RegExp.$1); […]

  • Reverse pre search in regular expressions (2)

    Time:2021-5-6

    The code is: Copy codeThe code is as follows: //The purpose of the program is to remove the domain name in the image pathvar str = ‘<img src=”https://imgs.developpaper.com/imgs/logo.gif”>’; var reg1 = /(\<img)(.*(?=(http|https)\:\/\/))((http|https)\:\/\/[^\/]*)/gim; str.match(reg1); alert(str.replace(RegExp.$4,”); This usage is applicable when there is only one URL in the string, but if the string contains multiple domain names, […]

  • JS common regular expression form validation code

    Time:2021-5-4

    Use of regular expressions brief introduction In short, regular expressions are a powerful tool for pattern matching and replacement. Its functions are as follows:A pattern of the test string. For example, you can test an input string to see if there is a phone number pattern or a credit card number pattern in the string. […]