'I am given a list of strings containing some booking ids and have to extract those booking ids from them
i = ["booking id is 5677","AE345RT is your booking id","booking id-3456","Booking id - ER3561"]
I have to extract thee booking ids from these strings, I am currently working in python3. the outputs will be-
5677,AE345RT,3456 and ER3561
Solution 1:[1]
With only one sample string it's not sure that we've covered all the cases. If the format is fixed then this python script shows how you can extract the required data.
You need to check that this works with all the possible variations and let me have more sample data if it's not working as needed.
import re
inputt = r'["booking id is 5677","AE345RT is your booking id","booking id-3456","Booking id - ER3561"]'
pattern = r'\["booking id is ([0-9]{4})","([A-Z]{2}[0-9]{3}[A-Z]{2}) is your booking id","booking id\-([0-9]{4})","Booking id - ([A-Z]{2}[0-9]{4})"]'
outputt=re.sub(pattern,r'\1,\2,\3 and \4',inputt)
print(outputt)
which prints out:
5677,AE345RT,3456 and ER3561
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
