python - Extract a string after some string -
i have text paragraph my_text contains lines
........ licensed in bangladesh. happy announce ...................... ................................................ i want extract word "bangladesh" it. decide if want word depends upon presence of "licensed in" in sentence.
current code like:
texts = my_text.split("licensed in") # extract word before first dot (.) texts[1] what more appropriate way in python?
that's job regex:
import re location = re.search(r"licensed in ([^.]*)", my_text).group(1) explanation:
class="lang-none prettyprint-override">licensed\ in\ # match "licensed in " ( # match , capture in grouping 1: [^.]* # number of characters except dots. ) # end of capturing grouping 1 python
No comments:
Post a Comment