• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Split string by space but exclude inside parentheses or balanced brackets

Resolved: Split string by space but exclude inside parentheses or balanced brackets

0
By Isaac Tonny on 16/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I have this expression:
And I want to break it up into these parts:
I have used the following regular expression:
But it does not give me the expected results. How can I make it work?

Answer:

You’d need recursion, but JavaScript’s regular expressions don’t have support for recursion. So create a simple parser that breaks down the string into words, and then keeps track of the depth of nesting parentheses. Collect the words, and each time that depth is 0, output (and clear) that collection:


If you have better answer, please add a comment about this, thank you!

javascript regex typescript
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: How to get Union type from an array of objects in Flow?

24/03/2023

Resolved: Modify entity using Action in C#

24/03/2023

Resolved: How to give rank on datetime column group by another column with userid in it

24/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.