Can I use (? = ...) | (? <= ...) instead of standalone (? = ...) or (? <= ...) in all cases?

My question

Can it be used lookahead|lookbehind

instead of standalone lookahead

or lookbehind

in all cases?

I just think

(?=...)|(?<=...)

looks like \b

In terms, we don't need to say that we want to use the left or right border of the word (or look from the back or front), but we just want to say that "any of them."

From this question What is the difference between \ b and \>, \ <in regex? :

We will see that instead of \<

and\>

we can use \b

And for (?=...)|(?<=...)

I'm not sure what is safe or not to say what we can use (?=...)|(?<=...)

instead of standalone (?=...)

or (?<=...)

in all cases.

If you have an example that (?=...)|(?<=...)

cannot be used instead (?=...)

or (?<=...)

please show me.

+3


source share


1 answer


Consecutive images are logical ANDs.
If you put them in between alternations, they are logical ORs.

You can include search queries.

(?=  a | (?<! b ) ) [^c]

      



which is equivalent

(?: (?= a ) | (?<! b ) ) [^c]

      

The thing to remember is that images are backtracking safe.
And when you enter a backlink, it maintains a separate search position.

0


source







All Articles