Regular regular expressions

time:10-09-03 forum:PHP tools and code
  Reprinted from http://www.im286.com/thread-5038534-1-1.html

letters, numbers, underlines and Chinese characters: /^[.quot;.Chr (0xa1)..quot; -.quot;.Chr (0xff)..quot; A-Za-z0-9_] $/ (GB2312) letters, numbers, underlines and Chinese characters. TF-8]

regular expressions are used for string processing, form validation, and so on, which are practical and efficient. Some commonly used expressions are collected here for emergency needs.

match the regular expression of Chinese characters: [\u4e00-\u9fa5]
comment: matching Chinese is really a headache, with this expression, the expression is good for the

match double byte characters (including Chinese characters):[^\x00-\xff]
comment: it can be used to calculate the length of a string (a double byte character. Length meter 2, ASCII character meter 1)

regular expressions matching blank lines: \n\s*\r
commentary: can be used to delete blank line

regular expressions that match HTML markings:.Lt; (\S*?) [^.gt;]*.gt; *.Lt; Matching part, a regular expression for complex nested tags still incapable of

matching the first and end blank characters: ^\s*|\s*$
comment: the blank characters (including spaces, tabs, paging, and so on) can be used to delete the end of the row, and a very useful tabular

regular table matching the Email address Form: \w (-.]\w) *@\w ([-.]\w) *\.\w ([-.]\w) *
commentary: the regular expression of

match URL URL: [a-zA-z]: //[^\s]*
comment: the version function of the version is limited on the Internet, the above basically can satisfy the requirement of the matching account number is legal (the letter begins, Allow 5-16 bytes, allow alphanumeric underline):^[a-zA-Z][a-zA-Z0-9_]{4,15}$
comment: form validation is very practical

match domestic phone number: \d{3}-\d{8}|\d{4}-\d{7}
comment: matching form such as 0511-4405222 or 021-87888822

match Tencent QQ: [1-9][0-9]{4,}
commentary



[1-9]\d{5} (?!!)
comment: Chinese postal code is 6 digit

commentary on matching sfz:\d{15}|\d{18}
: Chinese sFz is 15 or 18 bits

match IP address: >
match specific numbers:
^[1-9]\d*$/ / matching positive integer
^-[1-9]\d*$/ / matching negative integer
^[1-9]\d*|0$/ / / matching non negative integer (positive integer 0)
^-[1-9]\d*|0$/ / matching non positive integer (negative integer 0)
[>] *[1-9]\d*$/ / matched positive floating point number
~ ([1-9]\d*\.\d*|0\.\d*[1-9]\d*) $/ / matched negative floating point number
^[1-9]\d*\.\d*|0\.\d*[1-9]\d*|0? \.0 |0$/ / matching non negative floating point number (positive floating point number 0)
(- -9]\d*)) |0? \.0 |0$/ / matching non positive floating-point number (negative floating point number 0)
useful when dealing with large numbers of data, specific applications pay attention to correcting

matching specific strings:
^[A-Za-z] $/ / / matching string consisting of 26 English letters
^[A-Z] $/ / / matching by 26 English letters A string composed of
^[a-z] $/ / / matching string composed of 26 English alphabets
^[A-Za-z0-9] $/ / / matching string composed of numbers and 26 English alphabets
^\w $/ matching string consisting of numbers, 26 English letters, or underlines

prev:Dongbei ice cream machine 4600 yuan next:A hilarious magic trick of a mountain st...
post comment
Notice



approved   Online test site PING value, network...   Expired domain name query   Query the operation system informati...   Phoenix reporter Dunfee and others l...   BigDog big foot transport robot in t...
rand   Implementation of escape decoding fu...   PHP decryption of Unicode coded char...   PHP to get the breakpoint renewal co...   How to optimize Mysql tens of millio...   Formal release of PHP 5.3.6
ads

other

Because all the contents of this site are reproduced from other media, the intention is to provide free services to the public, but it does not mean that this site agrees with its views, and can not be responsible for the authenticity of its verification, such as the copyright unit or individual of the manuscript does not want to publish on this site, please Contact me, I will immediately remove it, thank you. Contact: atseashawk@163.com