December 2018
Intermediate to advanced
226 pages
4h 57m
English
There are times when an engineer wants to parse specific data from a sentence or a big chunk of data. Regex is the best tool of the trade for this purpose. Regex is a common concept in every programming language, with the only difference being the syntax in each programming language.
The following example shows how to use regex in Python:
import resample="From Jan 2018 till Nov 2018 I was learning python daily at 10:00 PM"# '\W+' represents Non-Alphanumeric characters or group of charactersprint(re.split('\W+', sample))#Extract only the month and Year from the string and print itregex=re.compile('(?P<month>\w{3})\s+(?P<year>[0-9]{4})')for m in regex.finditer(sample): value=m.groupdict() print ("Month: "+value['month']+" ...Read now
Unlock full access