My regex syntax is not returning the correct results. I have data returned from GitHub using the github3.py library that returns three possible strings when parsing through the patch key of md files (https://developer.github.com/v3/pulls/#list-pull-requests-files). I've read the regex documentation and several threads, but I'm missing something in my syntax.
string1 = '> [HELP.SELECTOR]'
string2 = '-> [HELP.SELECTOR]'
string3 = '+> [HELP.SELECTOR]'
I want to print True for the exact match to string2 or string3 and False if string1 is found. My results are returning False if string2 or string3 is found.
for prs in repo.pull_requests():
search_string_found = 'False'
regex_search_string1 = re.compile(r"^\+>\s\[HELP.SELECTOR\]")
regex_search_string2 = re.compile(r"^->\s\[HELP.SELECTOR\]")
for data in repo.pull_request(prs.number).files():
match_text1 = regex_search_string1.search(data.patch)
match_text2 = regex_search_string2.search(data.patch)
if match_text1 is not None and match_text2 is not None:
search_string_found = 'True'
break
print('HELP.SELECTOR present in file: ', search_string_found)
regex_search_string = re.compile(r"^[+-]>\s\[HELP\.SELECTOR\]"), then:if regex_search_string.search(data.patch):regex_search_string = re.compile(r"[\+-]>\s\[HELP\.SELECTOR\]").[+/-]is at the start of the string, such as+> [HELP.SELECTOR], but when I tested with the caret, incorrect results were coming back, but when I removed it, results were as expected.