Some commonly used to regular expressions

We often use some of the regular expression in the project, it will be used regular induction, easy to find late

A brief description of the regular characters

"^": ^ Matches the line or the starting position of the string, sometimes matching the starting position of the entire document
"$": $ matches the end of a line or string
"\ d": matching numbers
"\ s" : space match
"*": zero or more
"+": one or more times, at least once
, "?": ZeroOrOne
"{n}": n times
"{n, m}": n to m times
"{n,}": n or more times

1-50 letters or numbers and
  / ^ [A-Za-z0-9 ] {1,50} $ /

8-16 and the password is a combination of numbers and letters
  / ^ (?! [0-9] + $) (?! [A-zA-Z] + $) [0-9A-Za-z] {8, } $ 16 /

Mailbox format
  / ^ [\ w # $% &! '* + / = ^ _ `{|} ~ -?] + (:?.! \ [\ W # $% &' * + / = ^ _`? {|} ~ -] +) * @ (: [\ w] (: [\ w -] * [\ w]??) \) + [\ w] (: [\ w -] * [?.? \ w])? $ /

Phone number
  / ^ 1 [345789] \ d {9} $ /

Comprising the letters and numbers of
  / ^ [a-zA-Z0-9 \ u4e00- \ u9fa5] {1,29} $ /

Test whether all Chinese
  / [\ u4E00- \ u9FA5 \ uF900- \ uFA2D] /

Guess you like

Origin www.linuxidc.com/Linux/2019-11/161291.htm
Recommended