Last active
August 19, 2020 11:37
-
-
Save ansaso/86005f87afb4057f6d957f8281130d29 to your computer and use it in GitHub Desktop.
useful regex
This file contains hidden or 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
class usefulRegex: | |
def toggle(kwrd: str, match: str) -> str: | |
return r'(?:\W|\A)' + re.escape(kwrd) + r'[=: \'\"]+(' + re.escape(match) + r')' | |
def keyword(kwrd: str) -> str: | |
return r'(?:\W|\A)' + re.escape(kwrd) + r'[=: \'\"]+(?:\'(.+)\'|(\".+\")|(\S+))' | |
def value(kwrd: str, match: str=r'([\d.]+)') -> str: | |
return r'(?:\A|\W)' + re.escape(kwrd) + r'[ =:]*?' + re.escape(match) | |
def between(start: str, stop: str): | |
start = re.escape(start) | |
stop = re.escape(stop) | |
return r'(?:\A|\s)(?:' + start + r'){1}(?![' + start + r'])(.+?)(?<![' + stop + r'])(?:' + stop + r'){1}' | |
def split_list(): | |
return r'\A[ \'\"]|[ \'\"]*,[ \'\"]*|[ \'\"]\Z' | |
def start_includes(match: str): | |
return r'^(?:(?:\<.+\>| )|\W)+' + re.escape(match) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment