Skip to content

Instantly share code, notes, and snippets.

@Anwarvic
Last active August 2, 2018 10:21
Show Gist options
  • Select an option

  • Save Anwarvic/3a13d41ceabbdb628593297a79fbde63 to your computer and use it in GitHub Desktop.

Select an option

Save Anwarvic/3a13d41ceabbdb628593297a79fbde63 to your computer and use it in GitHub Desktop.
In this gist, I will write regular expressions for different purposes (incremental)
"""
extract names like:
Mohamed Anwar
Mohamed Anwar Ghanem
Mohamed Anwar Saeed Ghanem
but not:
Mohamed
Mohamed A. Ghanem
"""
regex = r'(([A-Z]{1}[a-z]+)\s){2,}'
###########################################
"""
extract numbers like:
1st, 2nd, 3rd, 4th
123
12.345
12.
01,234,567
"""
regex = r'(([0-9])+(th|st|nd|rd|\s))|([0-9]{0,2},([0-9]{3})+)|([0-9]+.[0-9]*)'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment