Skip to content

Instantly share code, notes, and snippets.

@eshafik
Last active January 4, 2020 15:54
Show Gist options
  • Select an option

  • Save eshafik/4b4e5364904930e706d6a62366d34cda to your computer and use it in GitHub Desktop.

Select an option

Save eshafik/4b4e5364904930e706d6a62366d34cda to your computer and use it in GitHub Desktop.
import re
text_1 = "I live in Bangladesh"
text_2 = "I speak Bangla"
textRegex = re.compile(r"Bangla(desh)?") # 0 or one time.
print(textRegex.search(text_1))
# Output:
<re.Match object; span=(10, 20), match='Bangladesh'>
print(textRegex.search(text_2))
# Output:
<re.Match object; span=(8, 14), match='Bangla'>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment