Python regex.I Examples
The following are 7
code examples of regex.I().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
regex
, or try the search function
.
Example #1
Source File: locale.py From dateparser with BSD 3-Clause "New" or "Revised" License | 6 votes |
def _get_simplifications(self, settings=None): no_word_spacing = eval(self.info.get('no_word_spacing', 'False')) if settings.NORMALIZE: if self._normalized_simplifications is None: self._normalized_simplifications = [] simplifications = self._generate_simplifications(normalize=True) for simplification in simplifications: pattern, replacement = list(simplification.items())[0] if not no_word_spacing: pattern = r'(?<=\A|\W|_)%s(?=\Z|\W|_)' % pattern pattern = re.compile(pattern, flags=re.I | re.U) self._normalized_simplifications.append({pattern: replacement}) return self._normalized_simplifications else: if self._simplifications is None: self._simplifications = [] simplifications = self._generate_simplifications(normalize=False) for simplification in simplifications: pattern, replacement = list(simplification.items())[0] if not no_word_spacing: pattern = r'(?<=\A|\W|_)%s(?=\Z|\W|_)' % pattern pattern = re.compile(pattern, flags=re.I | re.U) self._simplifications.append({pattern: replacement}) return self._simplifications
Example #2
Source File: date.py From dateparser with BSD 3-Clause "New" or "Revised" License | 6 votes |
def _try_hardcoded_formats(self): hardcoded_date_formats = [ '%B %d, %Y, %I:%M:%S %p', '%b %d, %Y at %I:%M %p', '%d %B %Y %H:%M:%S', '%A, %B %d, %Y', '%Y-%m-%dT%H:%M:%S.%fZ' ] try: return parse_with_formats( self._get_translated_date_with_formatting(), hardcoded_date_formats, settings=self._settings ) except TypeError: return None
Example #3
Source File: encryptionencoding.py From chepy with GNU General Public License v3.0 | 5 votes |
def from_morse_code( self, dot: str = ".", dash: str = "-", letter_delim: str = " ", word_delim: str = "\n", ): """Decode morse code Args: dot (str, optional): The char for dot. Defaults to ".". dash (str, optional): The char for dash. Defaults to "-". letter_delim (str, optional): Letter delimiter. Defaults to " ". word_delim (str, optional): Word delimiter. Defaults to "\\n". Returns: Chepy: The Chepy object. """ decode = "" morse_code_dict = EncryptionConsts.MORSE_CODE_DICT for k, v in morse_code_dict.items(): morse_code_dict[k] = v.replace(".", dot).replace("-", dash) morse_code_dict = {value: key for key, value in morse_code_dict.items()} for chars in self._convert_to_str().split(letter_delim): if word_delim in chars: print("here", chars) chars = re.sub(word_delim, "", chars, re.I) print(chars) if morse_code_dict.get(chars) is not None: decode += " " + morse_code_dict.get(chars) else: decode += morse_code_dict.get(chars) self.state = decode return self
Example #4
Source File: strtools.py From extratools with MIT License | 5 votes |
def extract(s: str, entities: Iterable[str], useregex=False, ignorecase=True) -> Iterable[str]: for m in re.compile( r"\b(?:{})\b".format(r"|".join( e if useregex else re.escape(e).replace(' ', r"s+") for e in entities )), re.I if ignorecase else 0 ).finditer(s): yield m.group(0)
Example #5
Source File: strtools.py From extratools with MIT License | 5 votes |
def extract(s: str, entities: Iterable[str], useregex=False, ignorecase=True) -> Iterable[str]: for m in re.compile( r"\b(?:{})\b".format(r"|".join( e if useregex else re.escape(e).replace(' ', r"s+") for e in entities )), re.I if ignorecase else 0 ).finditer(s): yield m.group(0)
Example #6
Source File: simple.py From epitran with MIT License | 5 votes |
def _construct_regex(self, g2p_keys): """Build a regular expression that will greadily match segments from the mapping table. """ graphemes = sorted(g2p_keys, key=len, reverse=True) return re.compile(r'({})'.format(r'|'.join(graphemes)), re.I)
Example #7
Source File: autosum_arxiv.py From autosum with MIT License | 5 votes |
def search_citation(sentences, exp): '''Finds sentences around citations, where the regexp `exp matches''' print("Search...'{0!s}'".format(exp)) rx = regex.compile(exp, flags=(regex.I)) founds = set() for sent in sentences: if rx.search(sent): founds.add(sent) return founds