Skip to content
Advertisement

How to parse and match with multiple regexes

I have an input data of the form:

JavaScript

I need to parse through this data and the IN: / OUT: /INOUT: depending on three regexes given as:

JavaScript

My output should be:

JavaScript

The code I tried:

JavaScript

The problem I face is that it does not parse correctly and it is not getting matched for each subdata beginning with [2]

Advertisement

Answer

Though I find the requirement quite strange(regex is provided and cannot change), I got the expected result. Can you try.

JavaScript

Update

For better performance, you can match only once, and get the groups. Take r1 as example:

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