Python 95th Day--js Regular

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.