[Tutor] bracket issue
Cameron Simpson
cs at zip.com.au
Tue Apr 18 03:06:45 EDT 2017
On 15Apr2017 14:05, Alan Gauld <alan.gauld at yahoo.co.uk> wrote:
>On 15/04/17 03:17, Palm Tree wrote:
>
>> s="2*3+3(8-4(5+6+9))+2+3+3(4/4)"
>>
>> i want to find expression enclosed in brackets.
>>
>> i want outputs to be like:
>> (8-4(5+6+9))
>> (5+6+9)
>> (4/4)
>>
>
>You probably could do it with some fancy regex but personally
>I'd investigate a proper text parser.
The nested brackets thing is something that regexps generally won't do fully,
because they don't recurse. You could write a regexp to handle up-to-n nestings
for some finite n, but as soon as that gets above something like 2 you're
probably into the "don't use regexps for this" domain.
Cheers,
Cameron Simpson <cs at zip.com.au>
More information about the Tutor
mailing list