I have a string "MenuItem {Open source}"
.
How can I get the string Open source
from my string?
e.g.
str1 = "MenuItem {Open source}"
perform some actions to set string two to be...
print str2 # 'Open source'
How can I acheive this using python or jython?
You can get it with a regular expression.
>>> import re
>>> str1 = "MenuItem {Open source}"
>>> re.search(r'{(.*)}', str1).group(1)
'Open source'
You can also get it by splitting the string on the {
and }
delimiters (here I use str.rsplit
rather than str.split
to make sure it splits at the right-most match):
>>> str1.rsplit('{')[1].rsplit('}')[0]
'Open source'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With