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]
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
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,
New Users, Read This
  • Use code tags when posting code.
  • Include any errors with your post (in code tags).
  • Describe your problem; not your chosen solution.
  • Make examples the minimum length to demonstrate your issue.
User avatar
Posts: 1711
Joined: Thu Feb 07, 2013 11:33 pm
Location: Tucson, Arizona

Return to General Discussions

Who is online

Users browsing this forum: No registered users and 4 guests