i have data of thousand records which i read line by line . Each line has some fields and their value but field names contain a non ascii character, below is the example of such a record :
| | | X:720 | N°227: Done
where X and N°(non ascii character) are fieldnames and 720,227 and “Done” are field values which i have to extract.
These fields are optional which may exist or may not .
Now I have to check whether these fields exist in line or not and if it exists then what is its value(for example X field is having value 720 and N° is having value 227 and “Done”)
Please let me know how to do this using regex in python ,is there any another way to do this in python?
Sometimes regex is good for such thing, sometimes
split()and other string method will be easier. It is up to you to chose:As for regexp:
\s*is zero or more white characters\S+is one or more non white character\dis for digits\Dis for non digits.means any characterrbefore string means “raw” string so you do not need to escape backslash