import re
def match_quotes(s):
    return re.findall(r"\"(.*?)\"", s)
if __name__ == "__main__":
    print match_quotes('Example of "quotation string" with several "quotes"')
Another one regex issue is to find a part of the string from the certain char till the end:
import re
def match_end_of_the_string(s, c):
    return re.findall(r"%s(.*?)$"%c, s)
if __name__ == "__main__":
    print match_end_of_the_string('Example of #commented string', "#")
Certainly, it's less obvious than split() approach. :)
No comments:
Post a Comment