Exemple #1
0
import re
from re2 import found

string1 = 'aba'
string2 = 'abba'
string3 = 'abbba'
string4 = 'abbbba'
regex = r'ab{2,3}a'

result1 = re.search(regex, string1)
found(result1)
result2 = re.search(regex, string2)
found(result2)
result3 = re.search(regex, string3)
found(result3)
result4 = re.search(regex, string4)
found(result4)
Exemple #2
0
import re
from re2 import found

string1 = 'Squirrels are better than chipmunks'
string2 = 'There_are_no_spaces'
regex = r'.* are .*'

result1 = re.search(regex, string1)
found(result1)
result2 = re.search(regex, string2)
found(result2)
import re
from re2 import found

string1 = 'Squirrels are better than chipmunks'
string2 = 'There_are_no_spaces'
regex = r'.* are .*' # Any number of characters, followed by space, followed by "are", followed by space, followed by any number of characters

result1 = re.search(regex, string1)
found(result1)
result2 = re.search(regex, string2)
found(result2)
Exemple #4
0
import re
from re2 import found

string = 'abababab'
regex = r'(ab)*'

result = re.search(regex, string)
found(result)