Answer the question
In order to leave comments, you need to log in
How to correctly compose a regular expression for cutting on ()?
Hello everyone..
There is a string: (name)(type)(percent)(who)
name - any string, spaces, -, and other characters..
desc - any number ([\d])
percent - any string, any characters
who - any string and characters
But (who) in the string is not always.
I got something like this:
/(\([\2 ]*\))[\s]*(\([\S ]*\))[\s]*(\([\S ]*\))[\s]*(\([\S ]*\))?/i
Answer the question
In order to leave comments, you need to log in
\((?<name>[^)]+)\)\((?<type>\d+)\)\((?<percent>[^)]+)\)(?:\((?<who>[^)]+)\))?
\(([^\)]*)\)\(([\d]*)\)\(([^\)]*)\)\(([^\)]*)\)
https://regex101.com/r/rN8tG2/1
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question