Html specific use on a regular string matching judgment and

Foreword
recently wrote a component, need to pass html string, which uses a lot of regular text, etc. to determine whether it is within the html tags or labels match, here recorded.
How to determine the incoming label string contains a closed html
/ <\ /? [AZ] [\ S \ S] > / I
of this fact, can not determine the integrity of the tag closing sequence or the like, but is determined whether a character string html tag (includes custom tags), that's enough for me up. This gives regular inside need to learn is [\ s \ S] can represent all the strings.
/ <([AZ] [\ S \ S]
)>. <\ / \ 1> / I
This is even more specification some of which may match a complete closure label \ captured content within represents foregoing parentheses is positive then the more advanced usage.
How to match the content within a text label
. 1
STR = str.replace (/ <title> [\ S \ S]
? <\ / Title> /, '<title>' + the newTitle + '<\ / title>') ;
Preferably with a semantic tag or custom tags do match, if div such a string may have a plurality of fine, many problems will be.
[sS] represent any character
behind? representatives of non-greedy mode, because the regular match is the default greedy pattern of
summary
matching text with html tags from being in fact a very inefficient way, not necessary when there is no need to go use, an essay deeply critical of this behavior are interested can look at.
Common regular expression
matching Chinese characters in regular expressions: [u4e00-u9fa5]
Commentary: matching Chinese really is headache, easy to handle with this expression
matching double-byte characters (including characters included): [^ x00-xff]
Commentary: can be used to calculate the length of the string (a double-byte character length meter 2, ASCII character count 1)
matching regular expression blank line: NS R & lt
commentary: to remove blank lines may
match the regular expression HTML tags: <(S
?) [^>] >. ? | <. /?>
Comment: the spread of the internet version too bad, above this was only able to match parts for complex nested tags still powerless
match and last blank character of the regular expression: ^ S
| S $
commentary: you can use to delete the beginning of the line trailing whitespace characters (including spaces, tabs, page breaks, etc.), very useful expression
matching Email address regular expression: w + ([-. +] w +)
@w + ([ . -] w +) . .w + ([-] w +)
commentary: when forms authentication is very useful br /> matching URL URL regular expression: ^ (http | https): \ / \ / [\ w \ -_] + (. \ [\ w \ -_] +) + ([. \ w \ - \, @ ^ =% &:? / ~ \ + #] * [\ w \ - \ @ ^ =% & /? ~ \ + #]) $?
Comment: the spread of the internet version of the function is very limited, above meet the basic needs of this
match Legality number (starting with the letter, allowing 5-16 bytes to allow alphanumeric underlined): ^ [a-zA- Z] [a-zA-Z0-9 _] {4,15} $
Commentary: when the form is very useful to verify
Domestic telephone number matching: d {3} -d {8 } | d {4} -d {7}
Comment: 0511-4405222 form such as a matching or 021-87888822
matching Tencent QQ: [1-9] [0-9 ] {4,}
Comment: Tencent QQ number from 10000 start
matching China Postal Code: [1-9] d {5} (?! d)
commentary: 6-digit ZIP code for China
match ID: d {15} | d {18}
commentary: China ID is 15 or 18
matches address ip: d + .d + .d + .d +
commentary: extracting useful ip address
matches a particular number:
  ^ [1-9] D $ n // match integer
  ^ - [1-9] d
$ // matching negative integers
  ^ - [1-9] d? $ match integer //
  ^ [1-9] d
| 0 // $ match non-negative integer (positive integer + 0 ) ^
  - [1-9] D | 0 $ // matching non-positive integer (negative integer 0 +)
  ^ [1-9] D
2.d | 0.d [1-9] D $ // matching positive float
  ^ - ([1-9] d
.d | 0.d [1-9] d ) $ // matching negative float
  ^ - ([1-9] d?
.d | 0.d [1-9] d | 0 .0+ |? 0) // $ match float
  ^ [1-9] d
.d | 0.d [1-9] d | 0 ?. 0+ | 0 $ // match non-negative floating-point numbers (positive float 0 +)
  ^ (- ([1-9] d
.d | 0.d [1-9] d )) | 0 .0+ |? 0 $ @ matches non-positive float (negative float + 0)
commentary: when processing large amounts of data useful for specific applications noted corrected
match a particular string:
  ^ [A-Za-Z] @ + matched by $ 26 string consisting of letters
  ^ [AZ] + $ // matching string of uppercase letters 26 composed
  ^ [az] + $ // matching string of 26 lowercase letters consisting of
  ^ [A- Za-z0-9] + $ // matching string of numbers and English letters of 26
  ^ w + $ // matched by the numbers 26 letters or underscore character string composed
on authentication using authentication control RegularExpressionValidator its expression is verified as follows:
only numbers: "^ [0-9]
$"
only n-bit digital input: "^ d {n} $ "
only n-bit digital input at least: "^ d { n,} $ "
only input digital mn bits:" ^ d {m, n } $ "
You can only enter a zero and non-zero number at the beginning: "^ (0 | [1-9] [0-9] ) $"
Enter only have two positive real number of decimal places: "^ [0-9] + (. ? [0-9] {2}) $ "
can only enter a positive real number from 1 to 3 decimal digit:."? ^ [0-9] + ([0-9] {1,3}) $ "
only can enter a positive integer zero: "? ^ + [1-9] [0-9]
$"
can only enter a non-zero negative integers: "^ - [1-9] [0-9] $"
only the length of the input characters 3: "^ {3} $."
only by the input string 26 English letters: "^ [a-Za- z] + $"
can only be entered by the uppercase English letters 26 string: "^ [AZ] + $ "
can only enter a string of letters written 26 small consisting of: "^ [az] + $ "
can only enter a string of numbers and the 26 English letters: " ^ [a-Za-z0-9] + $ "
only input string of digits, letters or underscore 26 consisting of:" ^ w + $ "
verify user password:" ^ [a-zA- Z] w { 5,17} $ "is the correct format: beginning with the letter, the length between 6-18 can only contain characters, numbers, and underscores.
Verify ^% & containing '?,; = $ "Characters such as:" [^% &' ' ,; = $ x22?] + "
Can input Chinese characters:" ^ [u4e00-u9fa5] , {0,} $ "
verify Email address:" W ^ + [-. +] + W)
@w + ([-.] + W) .W + ([-.] + W) $ "
Phone number verification: "^ ((d {3,4 }) | d {3,4} -) d {7,8} $?"
The correct format is: "XXXX-XXXXXXX", " XXXX-XXXXXXXX", " XXXXXXX-XXX ",
" XXX-XXXXXXXX "," XXXXXXX "," XXXXXXXX. "
ID verification number (15 or 18 digits): "^ d {15} | d {} 18 $"
verification year 12 months:? "^ (0 [1-9 ] | 1 [0-2 ]) $ "correct format:" 01 "-" 09 "and" 1 "" 12 "
verify a month 31 days:" ^ (? (0 [ 1-9]) | ((1 | 2) [0 -9]) | 30 | 31) $ "
correct format:" 01 "" 09 "and" 1 "" 31. "
Chinese characters matching the regular expression: [u4e00-u9fa5]
matching double-byte characters (including characters included): [^ x00-xff]
regular expression matching blank line: n-[S |] R & lt
matching regular HTML tags expression: / <(.
)>. | <(. /)> /
matching trailing spaces regular expression: (^ S ) | (S $)

Guess you like

Origin blog.51cto.com/yanhuang/2479929