Please enable JavaScript to use regex101
/
^
r
e
g
e
x
[
\
-
_
]
?
1
0
1
$
/
i
Reg
ular
Ex
pressions
101
Upgrade to Pro
Enterprise
Regular Expression
`
MY_STRING
`
gm
Input 1
[,]?\b(MY_STRING)\b[^,\r\n]*(?=;comment) PCRE(PHP) Im trying to match all MY_STRING considering that: * Exist a comma preceding it * No comma succeeding * Contains at the end of the line the string ;comment Examples: text,text MY_STRING ;comment -> match because theres a comma before MY_STRING and ;comment at the end line text,MY_STRING text ;comment -> match text,text MY_STRING %text% @text@ #text# ;comment -> match because exist a comma backward and ;comment at the end line MY_STRING ;comment -> dont match, because theres no comma before MY_STRING ,MY_STRING,text -> no match, because theres no ;comment at the end line MY_STRING, text, MY_STRING ;comment -> match ONLY the last MY_STRING MY_STRING , text MY_STRING, text -> no match, because theres no ;comment at the end line text MY_STRING ;comment -> no match because theres no comma before MY_STRING text,MY_STRING, text MY_STRING MY_STRING text ;comment -> match the last two MY_STRING MY_STRING,MY_STRING, text
Substitution
-------------
[,]?\b(MY_STRING)\b[^,\r\n]*(?=;comment) PCRE(PHP) Im trying to match all MY_STRING considering that: * Exist a comma preceding it * No comma succeeding * Contains at the end of the line the string ;comment Examples: text,text MY_STRING ;comment -> match because theres a comma before MY_STRING and ;comment at the end line text,MY_STRING text ;comment -> match text,text MY_STRING %text% @text@ #text# ;comment -> match because exist a comma backward and ;comment at the end line MY_STRING ;comment -> dont match, because theres no comma before MY_STRING ,MY_STRING,text -> no match, because theres no ;comment at the end line MY_STRING, text, MY_STRING ;comment -> match ONLY the last MY_STRING MY_STRING , text MY_STRING, text -> no match, because theres no ;comment at the end line text MY_STRING ;comment -> no match because theres no comma before MY_STRING text,MY_STRING, text MY_STRING MY_STRING text ;comment -> match the last two MY_STRING MY_STRING,MY_STRING, text