The zero width assertion of JS regular

Source: Internet
Author: User

The regular expression matches that we've learned are all "width" and will match with \w+。 The following text:

Regular Expression  

If you do not want to match the symbol, match only one position, use the "0 wide assertion" (Match width is zero, satisfy certain condition/assertion), 0 wide assertion use (? = expression) syntax, \w+(?=。) For example, where (?=。) represents the previous position (antecedent assertion)

Regular expression.  

If you need to match a later location, such as:

regular . expression  

Then use (?<=。) (?<=。)\w+ The post assertion to get the above matching result

Use (?<=<b>).*(?=</b>) content from a matching tag

<b> Bold </b>  
Negative 0 Wide Assertion

Negative to 0 wide assertion (?! Expression) is also a position that matches a 0 width, but the "assertion" of the position takes the inverse of the expression (?!表达式) , 表达式 For example to indicate the 表达式 previous position, if not, Match this position, if 表达式 It is, it does not match:

expression expression,expression, expression.       

The above is .+n(?!。) the matching result used. Note the difference from the match .+n[^。]

Expressionexpression,expression, expression.    

Similarly, negative 0-wide assertions also have "antecedent" and "post-hair" two, negative 0-wide after the assertion is (? <! expression)

Use (?<![</])para(?!>) match text below

<para>para represents a paragraph </para>    
    • (?<![</])Indicates that para the < left cannot be or / (?!>) is not the para right>

The zero width assertion of 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.