T
T
Timofey Mikhailov2017-10-06 14:36:46
JavaScript
Timofey Mikhailov, 2017-10-06 14:36:46

How to properly declare a regular expression?

Here is the working code:

var regul = /(AAA|BBB|CCC|DDD)\(.*?\)/g;
var str = "one two 12AAA(CCC(C1_1);A1_1)dfg dfgdfgdfg,BBB(B1_1; B1_2) sfsgndf dfgnhjdfglkjdfg DDD(D1_1)";
var ARR = str.match( regul );

for(var i = 0; i < ARR.length; i++) {
    console.log((i+1)+') '+ARR[i]);
}

But this code works if there are no other functions in the brackets ....
But if there is another function in the function, the script does not work correctly ..
It outputs the following:
1) AAA(CCC(C1_1)
2) BBB(B1_1; B1_2 )
3) DDD(D1_1)
Although, I would like to see:
1) AAA(CCC(C1_1);A1_1)
2) CCC(C1_1)
3) BBB(B1_1; B1_2)
4) DDD(D1_1) Tell me
how to fix it so that worked...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2017-10-06
@sergey_kzn

https://regex101.com/r/NGCAKn/1
https://regexper.com/#(AAA%7CBBB%7CCCC%7CDDD)%5C(....

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question