how to find position of below string?

A forum for general discussion of the Python programming language.

how to find position of below string?

Postby vijaykumbhani » Fri Aug 16, 2013 5:49 am

string = ( ( 2 + 3 ) + 2 ) + 2
find position of first round bracket and last round bracket ?

Mekire: I have deleted your other post. You need to show some level of effort to get assistance. "Give me regular expression" is not sufficient. Make an attempt and post it with the error you encountered or an explanation of how the output was not what you wanted.
[b][i]With Regards,
Vijay Kumbhani[/i][/b]
vijaykumbhani
 
Posts: 33
Joined: Wed Aug 14, 2013 4:26 am
Location: Surat, Gujarat, India

Re: how to find position of below string?

Postby Mekire » Fri Aug 16, 2013 6:25 am

You should really try to show more effort with your questions.

You could find the first and last parens with str.find() and str.rfind().

However, I also think you aren't looking at the problem correctly (not that you stated the problem).
Consider the equation:
Code: Select all
(2+3)+(2+2)
The first and last parenthesis don't actually match each other. You need to use a push down automata of sorts to find the matching parenthesis. The re module might be able to handle this though technically this isn't regular.

Try some stuff; then post what you tried,
-Mek
User avatar
Mekire
 
Posts: 977
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan


Return to General Discussions

Who is online

Users browsing this forum: No registered users and 1 guest