Aug-08-2022, 10:05 AM
Regex could be a solution:
Don't forget to select on the left side Python
Joke: If you have a problem and want to solve it with regex, then you have two problems.
import re def on_off_finder(in_string): values = ("off", "on") # index [ 0 ] [ 1] # bool(0) -> False # bool(1) -> True if match := re.search(r"ch=(on|off)", in_string.lower()): # it does only match, if ch=on or ch=off was # in_string.lower() # then getting the group1, which is in parentheses # then searching the index for off/on # converting the index (0 or 1) into bool # return this value return bool(values.index(match.group(1))) else: # ch=on or ch=off was not in_string.lower() return FalseTo check the regex, visit: https://regex101.com/
Don't forget to select on the left side Python
Joke: If you have a problem and want to solve it with regex, then you have two problems.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!