RegEx
Last updated
Last updated
Test tool for js:
For Ruby:
Debug regex:
Cheat Sheet:
See
Be careful about the greedy matching .*
, try to add ?
to use lazy matching: .*?
. See
Positive lookahead (does incldue): (?=...)
Negative lookahead (not include multiple chars): (?!...)
to match a single char that's not in the list, you can use [^abc]
(means match one char that's not a or b or c)
Positive lookbehind: (?<=...)
NOTE JavaScript doens't have this. You can use negative lookahead
"name" : "basic"
to "xxx" : "whatever you provided"
?Use negative lookahead: /^(?!.*po\sBOX).*$/
Let's say we want to match and replace :user
in the url abc.com/:user/notebooks/:user-name/:userName
Use We could use: /:user(?=\b)/
, which will match the first :user
and :user-name
but not :userName
.
use word boundary: \b
be sure to be lazy (+?)
using grouping for everything:
The lookbehind assertion (?<=foo_bar) is important because you don't want to include %download%# in your results, only the numbers after it.