Skip to main content

Posts

Showing posts with the label regular expressions

Python - Parsing or Regular Expression or Regex or RE (search, split, findall)

🐍  Parsing is way too simple in python. Basic parsing is done using the library re (Regular Expression). TRY ON JUPYTER NOTEBOOK Following should be the first line to start using functionalities of Regular Expressions: import re re.search(pattern, text) import re text = 'This is a string with term1, but it does not have the other term.' pattern = 'term1' print(re.search(pattern, text)) This will search 'term1' in the text and return Details, since it found it in the text. import re text = 'This is a string with term1, but it does not have the other term.' pattern = 'term2' print(re.search(pattern, text)) This will search 'term2' in the text and return 'None', since it didn't find it. re.search(pattern, text).start() It return the position of the first character of the pattern you are searching in the text. import re text = 'This is a string with term1, but it does not have the other term...