Skip to content
Advertisement

Regex expression not returning entire term

The intention of the regex is to capture substrings wrapped between twin expressions in parentheses, kinda like html tags. For example:

JavaScript

And here’s my code

JavaScript

JavaScript
JavaScript

Can anyone tell me why this doesn’t capture the entire thing?

Advertisement

Answer

The characters () are special in a regexp and must be escaped with a if you want to match them literally. And because in a JavaScript string literal is also special, it needs to be escaped with another :

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement