Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
104
rated 0 times [  106] [ 2]  / answers: 1 / hits: 43487  / 12 Years ago, thu, april 26, 2012, 12:00:00

I tried different ways to escape the parentheses using regex in JavaScript but I still can't make it work.



This is the string:



abc(blah (blah) blah()...).def(blah() (blah).. () ...)


I want this to be detected:



abc().def() 


Using this code, it returns false.



 str.match(/abc([^)]*).def([^)]*)/i);


Can you please tell me why my regex is not working?


More From » regex

 Answers
5

This regex will match the string you provided:



(abc().+().def().+())


And using backreferences $1$2$3 will produce abc().def()



Or just use this if you don't want the back references:



abc(.+).def(.+)

[#85970] Wednesday, April 25, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
brodyfrancisi

Total Points: 1
Total Questions: 102
Total Answers: 89

Location: Marshall Islands
Member since Mon, May 31, 2021
3 Years ago
brodyfrancisi questions
;