DEV Community

Nawaz Mujawar
Nawaz Mujawar

Posted on

How to match the backslash \ in Regular Expression?

I want to match <>/\":;=|*? these characters in the string, I tried this expression
<>/\":;=|*?
But It didn't work for me.
Please help me out.

Top comments (2)

Collapse
 
ash_bergs profile image
Ash

I'm in need of a little more context on your problem... but I plugged your Regex into this really handy tool that I use all the time when I'm debugging my own Regex code: regexr.com/

It basically just reads out what you're doing, and you can see if it's what you expected.

The first problem I see is you have an unescaped forward slash, and it looks like you're using an alternate (the | operator, that compiles to a boolean).

In general I know that the backslash is hard to match for in Regex, because by nature they're not really supposed to be used (other than for escaping), and it might require a really big, sort of ugly expression like the one in this StackOverflow thread: stackoverflow.com/questions/402548...

Sorry I couldn't do more, but I hope this helps!

Collapse
 
nawazmujawar profile image
Nawaz Mujawar

Thanks for the try