How do i write a regex that matches the syntax in either perl ruby javascript
The syntax is like /my pattern here/modifiers where modifiers are i, g and other single letters.
I wrote the below however that wouldn’t allow me to escape escape / with using . AFAIK i can write /Test\/Pattern/i in those languages to match the text Test/Pattern
/[^/]+/[^ ]*
You need to take into account that the
/might occur in the regular expression. But there is must be escaped. So:Here
([^\\/]|\\.)matches either any character except\and/or an escaped character.Furthermore, you often don’t need to escape the
/if it’s inside a character class, so:Here
\[([^\\\]]|\\.)*]matches a literal[followed by zero or more either any character except\and]or an escape sequence, followed by the literal].Additionally, modifiers are only alphabetic characters: