Summary of extjs regular expressions

Time:2021-4-3

Regular expressions that can be used in extjs

“^ D + $” / / non negative integer (positive integer + 0)
“^ [0-9] * [1-9] [0-9] * $” / / positive integer
“^ ((- – D +) | (0 +)) $” / / non positive integer (negative integer + 0)
“^ – [0-9] * [1-9] [0-9] * $” / / negative integer
“^ -? – D + $” / / integer
“^ D + (\. [D +)? $” / / non negative floating point number (positive floating point number + 0)
“^ (([0-9] + \. [0-9] * [1-9] [0-9] *); ([0-9] * [1-9] [0-9] * \. [0-9] +); ([0-9] * [1-9] [0-9] *) $” / / positive floating point number
“^ (- D + (\. [D +)?) | (0 + (\. 0 +)?) $” / / non positive floating point number (negative floating point number + 0)
“^ (- (([0-9] + \. [0-9] * [1-9] [0-9] *); ([0-9] * [1-9] [0-9] * \. [0-9] +); ([0-9] * [1-9] [0-9] *)) $” / / negative floating point number
“^ (-? – D +) (\. [D +)? $” / / floating point number
“^ [a-za-z] + $” / / a string of 26 English letters
“^ [A-Z] + $” / / a string of 26 upper case English letters
“^ [A-Z] + $” / / a string composed of 26 lowercase English letters
“^ [a-za-z0-9] + $” / / a string composed of numbers and 26 English letters
“^ W + $” / / a string of numbers, 26 letters or underscores
“^ [[w -] + (\. [w -] +) * @ [[w -] + (\. [w -] +) + $” / / email address
“^[a-zA-z]+://(\w+(-\w+)*)(\.(\w+(-\w+)*))*(\?\S*)?$”  //url
/^(D {2} | D {4}) – ((0 ([1-9] {1})) | (1 [1-2]) – ([0-2] ([1-9] {1})) | (3 [0-1])) $/ / / year month day
/^((0 ([1-9] {1})) | (1 [1-2]) / ([0-2] ([1-9] {1})) | (3 [0-1]) / (D {2} D {4}) $/ / / month / day / year
“^([w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$” //Emil
“(D + -)? (D {4} -? D {7} | D {3} -? D {8} | ^ D {7,8}) (- D +)?” / / phone number
“^ (D {1,2} | 1DD | 2 [0-4] d | 25 [0-5]) (D {1,2} | 1DD | 2 [0-4] d | 25 [0-5]) (D {1,2} | 1DD | 2 [0-4] d | 25 [0-5]) (D {1,2} | 1DD | 2 [0-4] d | 25 [0-5]) $” / / IP address

Regular expressions matching Chinese characters: [[u4e00 – [u9fa5]
Matching double byte characters (including Chinese characters): [^ / X00 – / XFF]
Regular expressions that match empty rows are as follows: n [\ s |] * \ R
Regular expressions matching HTML Tags: / < (. *) >. * < \ / – 1 > | < (. *) \ / >/
Regular expressions matching leading and trailing spaces: (^ s *) | (< s * $)
Regular expression matching email address: W + ([-.] – W +) * @ \ W + ([-.] – W +) * \. W + ([-.] – W +))*
Regular expression matching URL: ^ [a-za-z] +: / / (\ \ W + (- \ \ W +) *) (\ \. (\ \ W + (- \ \ W +) *) * (\ \? \ \ s *)$
Whether the matching account number is legal (starting with a letter, 5-16 bytes allowed, alphanumeric underscores allowed): ^ [a-za-z] [a-za-z0-9_ ]{4,15}$
Matching domestic phone number: (- D {3} – | – D {4} -)? (- D {8} | – D {7})?
Match Tencent QQ number: ^ [1-9] * [1-9] [0-9]*$

The following table is a complete list of metacharacters and their behavior in the context of regular expressions:

\To escape a character, a reference, or a special character.

^Matches the start of the input string. If the multiline property of the regexp object is set, ^ also matches the position after ‘\ n’ or ‘\ R’.

$matches the end of the input string. If the multiline property of the regexp object is set, the $also matches the position before ‘\ n’ or ‘\ R’.

*Matches the preceding subexpression zero or more times.

+Matches the previous subexpression one or more times. +It is equivalent to {1,}.

Matches the preceding subexpression zero or once. ? is equivalent to {0,1}.

{n} N is a nonnegative integer that matches the determined n times.

{n,} n is a nonnegative integer that matches at least N times.

Both {n, m} m and N are non negative integers, where n < = M. The minimum number of matches is n and the maximum number of matches is m. There cannot be a space between a comma and two numbers.

? the matching pattern is non greedy when the character is immediately followed by any of the other restrictors (*, +,?, {n}, {n,}, {n, m}). The non greedy pattern matches as few strings as possible, while the default greedy pattern matches as many strings as possible.

. matches any single character except “\ n”. To match any character including ‘\ n’, use a pattern like ‘[. [n]’.
(pattern) matching.

(?: pattern) matches the pattern but does not get the matching result, that is to say, it is a non acquisition matching and will not be stored for later use.

(? = pattern) forward look-up, which matches the search string at the beginning of any string matching pattern. This is a non fetch match, that is, the match does not need to be fetched for later use.

Negative preview of (?! pattern) is opposite to (? = pattern)

X | y matches X or y.

[XYZ] character set.

[^ XYZ] negative character set.

[A-Z] character range, matching any character within the specified range.

[^ A-Z] negative character range, matches any character that is not in the specified range.

\B matches a word boundary, that is, the position between the word and the space.

\B matches non word boundaries.

\CX matches the control character indicated by X.

\D matches a numeric character. Equivalent to [0-9].

\D matches a non numeric character. Equivalent to [^ 0-9].

\F matches a page feed. It’s equivalent to ⁃ x0c and ⁃ CL.

\N matches a newline character. It’s equivalent to ⁃ x0a and ⁃ CJ.

\R matches a carriage return. It’s equivalent to ⁃ x0d and ⁃ cm.

\S matches any white space character, including spaces, tabs, page breaks, and so on. It is equivalent to [(F / N / R / T / V)].

\S matches any non blank characters. It is equivalent to [^ ﹣ f ﹣ n ﹣ R ﹣ t ﹣ v].

\T matches a tab. It’s equivalent to ⁃ X09 and ⁃ CI.

\V matches a vertical tab. It’s equivalent to ⁃ x0B and ⁃ CK.

\W matches any word character that includes an underline. Equivalent to ‘[a-za-z0-9]_ ]’。

\W matches any non word character. Equivalent to ‘[^ a-za-z0-9]_ ]’。

\Xn matches n, where n is the hexadecimal escape value. The hexadecimal escape value must be two digits long.

\Num matches num, where num is a positive integer. A reference to the obtained match.

\N identifies an octal escape value or a backward reference. If there are at least n acquired subexpressions before, then n is a backward reference. Otherwise, if n is an octal digit (0-7), then n is an octal escape value.

\Nm identifies an octal escape value or a backward reference. If there are at least is preceded by at least nm subexpressions obtained before, nm is a backward reference. If there are at least n fetches before, then n is a backward reference followed by the character M. If the previous conditions are not satisfied, if n and m are octal digits (0-7), then the escape value nm will match the octal escape value nm.

\NML if n is an octal number (0-3), and m and L are both octal numbers (0-7), then the octal escape value NML is matched.

\UN matches n, where n is a Unicode character represented by four hexadecimal digits.

Regular expression matching Chinese characters: [u4e00-u9fa5]

Matching double byte characters (including Chinese characters): [^ X00 XFF]

Application: calculate the length of the string (a double byte character length of 2, ASCII character length of 1)

String.prototype.len=function(){return this.replace([^x00-xff]/g,”aa”).length;}

Regular expressions matching empty lines: n [s |] * r

Regular expressions matching HTML Tags: / <. * >. * < / 1 > | <. * / >/

Regular expression matching leading and trailing spaces: (^ s *) | (s * $)

Application: there is no trim function like VBScript in JavaScript, so we can use this expression to realize it, as follows:

String.prototype.trim = function()
{
return this.replace(/(^s*)|(s*$)/g, “”);
}

Using regular expression to decompose and translate IP address

The corresponding IP address is converted to the following regular expression:

function IP2V(ip)
{
Re = / (D +). (D +). (D +). (D +) / g / / regular expression matching IP address
if(re.test(ip))
{
return RegExp.$1*Math.pow(255,3))+RegExp.$2*Math.pow(255,2))+RegExp.$3*255+RegExp.$4*1
}
else
{
throw new Error(“Not a valid IP address!”)
}
}

However, the above program may be simpler if it is directly decomposed by split function instead of regular expression. The program is as follows:

var ip=”10.100.20.168″
ip=ip.split(“.”)
Alert (“IP value is: + (IP [0] * 255 * 255 * 255 + IP [1] * 255 * 255 + IP [2] * 255 + IP [3] * 1))

Regular expression matching email address: W + ([-.] W +) * @ w + ([-.] W +) *. W + ([-.] W +)*

Regular expression matching URL: http: / / ([w -] +.) + [w -] + (/ [w -. /?%, = = *)?

Using regular expression to remove repeated characters in string algorithm program:

var s=”abacabefgeeii”
var s1=s.replace(/(.).*1/g,”$1″)
var re=new RegExp(“[“+s1+”]”,”g”)
var s2=s.replace(re,””)
Alert (S1 + S2) / / the result is: abcefgi

I used to post on CSDN to find an expression to remove duplicate characters, but I didn’t find it. This is the simplest way I can think of. The idea is to use backward reference to extract the repeated characters, and then use the repeated characters to establish a second expression, and get the non repeated characters, and the two are concatenated. This method may not apply to strings that require character order.

A JavaScript program that uses a regular expression to extract the file name from the URL address. The result is page1

s=”https://www.jb51.net/page1.htm”
s=s.replace(/(.*/){0,}([^.]+).*/ig,”$2″)
alert(s)

Use regular expressions to restrict the input content of text box in web form

Limit the input to Chinese only with regular expression: onkeyup=“ this.value=this . value.replace (/[“^u4E00-u9FA5]/g,”)” onbeforepaste=” clipboardData.setData (‘text’, clipboardData.getData (‘text’).replace(/[^u4E00-u9FA5]/g,”))”

Use regular expressions to limit the input of full width characters: onkeyup=“ this.value=this . value.replace (/[“^uFF00-uFFFF]/g,”)” onbeforepaste=” clipboardData.setData (‘text’, clipboardData.getData (‘text’).replace(/[^uFF00-uFFFF]/g,”))”

Use regular expressions to limit only numbers: onkeyup=“ this.value=this . value.replace (/[“^d]/g,”) “onbeforepaste=” clipboardData.setData (‘text’, clipboardData.getData (‘text’).replace(/[^d]/g,”))”

Use regular expressions to limit only numbers and English: onkeyup=“ this.value=this . value.replace (/[W]/g,””) “onbeforepaste=” clipboardData.setData (‘text’, clipboardData.getData (‘text’).replace(/[^d]/g,”))”

Recommended Today

Talk about uiscrollview

First, before we talk about uiscrollview, let’s first understand how coordinate systems work in UIKit. Coordinate system Because everyviewDefines its own coordinate system, which looks like this: the X axis points to the right and the Y axis points down (as shown in the following figure). Logical coordinate system png However, it should be noted […]