Regex to search with parentheses
Regex to search with parentheses
Hello,
I have a problem with searching using Regex. The following expression was used to search for a term in one of my columns:
^(\bGround\b)$
And the following is used when searching for multiple at the same time
^(\bGround\b)|(\bAir\b)$
Both work fine when searching, but when I have a value with a parentheses like "Ground (0)" and use the following to search for it, I get no data back
^(\bGround \(0\)\b)$
I figured that you could escape the parentheses like a normal regex expression, but it doesn't seem to work.
Appreciate any help with this. Thanks!
Replies
In Javascript you need to escape the backslash with a backslash. The Javascript expression should look like this
^(\\bGround \\(0\\)\\b)$. If this doesn't help please provide a test case showing the issue.Kevin
http://live.datatables.net/wugafado/5/
Here's a perfect example.
Other things we are trying to filter are "Ground ($0)"
Looks like the problem is with the final
\b. There isn't a word character (letter or number) for the\bto apply too. See this info on word boundaries. I'm not sure off the top of my head what the best regex would be. A good place to experiment with regualr expressions is https://regex101.com/ .Kevin
Okay thanks for the response. I believe that you are correct. I've experimented for a while and can't figure out which would work best.
I will respond if I find a better alternative.
Thanks!
For anyone that comes here lookin for the solution. This is the solution I've come up with. Here's an example Regex
http://live.datatables.net/wugafado/7/edit