1

In JavaScript, I want to find all instances of text in the HTML that: start with (( and end with )). Here is what i currently have:

/^\(\(([a-zA-Z0-9\s\?\&\=\#\.\_\/\-\%\\]{1,})\)\)$/;

But it's not working.

How would i implement this? Thanks!

4
  • 2
    "But it's not working." Can you include example input string and expected result at Question? See stackoverflow.com/help/mcve Commented Jan 12, 2017 at 18:48
  • Your current regex tests for an entire string that begins with (( and ends with )), so it will fail if you're testing it on strings like something ((hello)) other thing because that string doesn't start/end with (( and )). You haven't shown how you're using this regex, and it's not clear if that behavior is different from what you want. Commented Jan 12, 2017 at 18:52
  • Having the ^$ characters where they are means that whatever string you are searching, will only return a match if that entire string matches your search. eg, "^abc$" will find a match for the string "abc", but not "1abc2". Commented Jan 12, 2017 at 18:53
  • ok i get it. I wanted to achieve something like how angular does their data-binding. Thanks. Commented Jan 12, 2017 at 22:09

1 Answer 1

4

Try this regular expression:

var regExDoubleParentheses = /\(\(.*?\)\)/g;

You can test it out here.

Sign up to request clarification or add additional context in comments.

1 Comment

I assume the OP is looking for "tokens". If not, don't use .*, use [^]* instead, as that will include any CRLF in the text.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.