Ad

How To Print Words From A String Up To A Point In Python

- 1 answer

I have created a script in Python which prints the word following a certain string in a csv file.

The code I have is:

    `import re
    file=open("csvfile.csv", "r")
    text=file.read()
    data=re.findall('(?<=originalName\=\')\w+',text)
    print data`

This works, however I want to print the words up until the character " in the string. Currently it only prints out the first word and the originalName could range from one to many words.

Thanks

Ad

Answer

You can use this regex. Which matches all characters until "

re.findall("(?<=originalName\=\')[^\"]*",text)
Ad
source: stackoverflow.com
Ad