The regex expression and the next character are not '('

I want to have an expression where the next character after the found value is not "(".

I have the following basic regex:

(([_A-Za-z]([_\w])+)|([A-Za-z]))

and text, for example:

a3+red+42+_dv+Sy(w12+44)

The expected regular expression should be returned:

a3, red, _dv, w12

this basic regular expression returns

a3, red, _dv, Sy, w12

but I need to exclude "Sy" because the next character is "(".

I try the following:

(([_A-Za-z]([_\w])+)|([A-Za-z]))(\b)

but he returns

a3+, red+, _dv+, w12)

I do not need to have the next character, I only need to include it if the next character is not "(".

+4
source share
2 answers

You need to do three things:

  • (, , , )

  • ( )

  • lookahead ,

:

\b((?>[_A-Za-z]\w+)|[A-Za-z]\b)(?!\()

1 : Abcd( Abc. , Abcd, , .

:

\b(?>[A-Za-z]\w*|_\w+)(?!\()
+4

_ , :

\b[^\W\d]\w*+(?!\()

. regex101

+ * possessive, lookahead.
\b ( regex101).

+1

Source: https://habr.com/ru/post/1662734/


All Articles