SoFunction
Updated on 2025-03-02

JS regular expression position matching

The above website can be used to detect regular expression syntax of JS online

In addition to a few well-known fixed characters representing positions:

^ : Match the beginning of the string and, in multiline searches, the beginning of a line.

$ : Match the end of the string and, in multiline searches, the end of a line.

\b: 

Match a word boundary. That is, match the position between a \w character and a \W character or between a \w character and the beginning or end of a string. (Note, however, that [\b] matches backspace.)

\B: Match a position that is not a word boundary.

Another thing is to use regular expressions to determine the location to match, also called Zero-Width Test (zero-width assertion)

(?=p) :

A positive lookahead assertion. Require that the following characters match the pattern p, but do not include those characters in the match.

(?!p) :

A negative lookahead assertion. Require that the following characters do not match the pattern p.

For (?=p)and(?!p) Use an example:

To be in url(skins/default/images/index/defaultMatch "default" in "/default/" in .png) and not "default" in "/"?

Regular expressions:(?!\/)default(?=\/)

in(?!\/)It means that it starts with "/",(?=\/)Indicates ending with "/"