Recovering text between parentheses using regexp
43 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Giri
am 7 Mai 2018
Kommentiert: Fangjun Jiang
am 7 Mai 2018
Hi,
I am trying to create a regular expression using which i can recover the string between two parenthesis. I have created the following expression
exp='[^(]+.*[^)]+';
matchStr = regexp(str,exp,'match');
This expression works fine if the string is off any one of the formats mentioned below:
a) str = '(1r)';
b) str = '(0.5;0.5;'rrr')'; etc
but does not work if the string is off the form
str = '(r)'; or str = '(1)';
i.e. it doesn't pick up string which are just off 1 character between the parenthesis. I think i am missing something very basic here. Is it that regex will not work for single characters and will only work for strings?
Thanks in advance,
Regards,
Giri
Akzeptierte Antwort
Fangjun Jiang
am 7 Mai 2018
exp = '[^()]*'; should be it.
2 Kommentare
Fangjun Jiang
am 7 Mai 2018
doc regexp
[^c1c2c3]: Any character not contained within the brackets.
expr*: 0 or more times consecutively.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu String Parsing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!