Created
April 3, 2012 02:46
-
-
Save solomon081/2288937 to your computer and use it in GitHub Desktop.
Both ReS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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