Skip to content

Instantly share code, notes, and snippets.

@solomon081
Created April 3, 2012 02:46
Show Gist options
  • Save solomon081/2288937 to your computer and use it in GitHub Desktop.
Save solomon081/2288937 to your computer and use it in GitHub Desktop.
Both ReS
import re
text = input("Enter your text: ")
pattern = input("Enter your pattern: ")
for match in re.finditer(pattern, text):
s = match.start()
e = match.end()
print("Found: ", pattern, "at:", s, "-", e)
import re
tex = input("Enter your text: ")
patt = input("Enter what you would like to match it to: ")
match = re.search(patt, tex)
if match == None:
print("No Match")
else:
start = int(match.start()) + 1
end = int(match.end()) + 1
if start == end:
print("Invalid pattern or text")
exit()
print("Match starts at character:", start)
print("Match ends at character:", end)
print("String Entered:", match.string)
print("Pattern Entered:", match.re.pattern)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment