Defining Regular Expressions
/.../for defining regular expressions
/.../g represents a global match
/.../i indicates case insensitive
/.../m for multi-line matching
JS regex matches itself to support multiple lines, where multiple lines match only affect the regular expression ^ and $,m mode will also use ^$ to match the contents of the newline)
var pattern =/^java\w*/gm; " JavaScript is more fun than \njavaee or javabeans! " ; = Pattern. exec (text) = Pattern. exec (text) = Pattern. exec (text)
Method: 1, test-determine whether the string conforms to the specified regular
' UUI99SDF ' =/\d+/ reg.test (n) ---> true # matches as long as the regular is present in the string, If you want to match the beginning and the end, you need to add ^ and $ before the regular
2. exec-Get matching data
exec(String) Gets the contents of the regular expression match, if it does not match, the value is null, otherwise, gets the array that matches successfully. Gets the contents of the regular expression match, if it does not match, the value is null, otherwise, gets the array that matches successfully. The non-global pattern gets an array of matching results, note that the first element is the first matching result, and the following element is a regular sub-match (regular content grouping match) var pattern=/\bjava\w*\b/; var text="JavaScript is more fun than Java or javabeans!"; Result= Pattern.exec(text) var pattern=/\b (Java) \w*\b/; var text="JavaScript is more fun than Java or javabeans!"; Result= Pattern.exec(text) The global schema needs to call the Exec method repeatedly, one to get the result until the match get result is null to get the complete var patte RN=/\bjava\w*\b/G; var text="JavaScript is more fun than Java or javabeans!"; Result= Pattern.exec(text) var pattern=/\b (Java) \w*\b/G; var text="JavaScript is more fun than Java or javabeans!"; Result= Pattern.exec(text)
3. Related methods in string
Obj.search (regexp) gets the index position, searches the entire string, returns the first position where the match succeeded (the G mode is invalid) Obj.match (regexp) gets the match, searches the entire string, Gets the first match found, if the regular is G mode finds all Obj.replace (regexp, replacement) replaces the match substitution, and G in the regular replaces all, or replaces only the first match, $ Number: Matches the nth group content; $&: Current matching content; $ ': text to the left of the matched substring; $': Text on the right side of the matching substring $$: Direct Volume $ symbol
Login Registration Verification
Form validation----Reduce database requests
Front-end JS verification
Back-end Python implementations
<form> <inputtype= ' text '> <inputtype= "Password"/> <inputtype= ' Submit '> </form> <Script> $(': Submit'). Click (function(){ $(": Text,:p assword"). each (function(){ .... return false; }) return false; }) </Script>
Python 95th Day--js Regular