0

I would like to write a regular expression to match two parentheses ( between $'s (not necessarily consecutive).

For example$c(ad(b*$, $a((*b$ and $$*(a(b(*$$ are match but $a($ and $(a)$ are not.

2

A dollar sign [$], followed possibly by some chars that are neither a dollar sign nor a left paren [^$(]*, followed by a left paren [(], followed (again) possibly by some chars that are neither a dollar sign nor a left paren [^$(]*, followed by a dollar sign [$].

"[$][^$(]*[(][^$(]*[(].*[$]"
  • Why not \$[^$(]*([^$(]*(.*\$? – PythonNut Jun 4 '15 at 21:10
  • 1
    No reason not. I thought the version I gave might be more self-explanatory. No need to know that ( is not special or to know how to escape special chars such as $. (And yes, if it were for my own code, I would write what you wrote.) – Drew Jun 4 '15 at 21:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.