Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RegEx match single character that is not follow by a character

Tags:

regex

I have a Regex that is almost what I need. I am sure this is a repeat of a repeat however I can't find the answer I am looking for.

Regex I need is an expression that will match a parenthesis that is not followed by a space, however I only want it to match the parenthesis.

(\([^\s])

This will match all parenthesis that are not followed by a space, however it matches the character that is directly after the parenthesis as well. How do I only get a match for the parenthesis?

like image 497
Richard Christensen Avatar asked Oct 21 '22 23:10

Richard Christensen


1 Answers

Use zero width assertion lookahead

\((?=\S)

or

\((?=[^\s])
like image 54
Anirudha Avatar answered Nov 02 '22 23:11

Anirudha