本文整理汇总了Python中regex.I属性的典型用法代码示例。如果您正苦于以下问题:Python regex.I属性的具体用法?Python regex.I怎么用?Python regex.I使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类regex
的用法示例。
在下文中一共展示了regex.I属性的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_simplifications
# 需要导入模块: import regex [as 别名]
# 或者: from regex import I [as 别名]
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
示例2: _try_hardcoded_formats
# 需要导入模块: import regex [as 别名]
# 或者: from regex import I [as 别名]
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
示例3: from_morse_code
# 需要导入模块: import regex [as 别名]
# 或者: from regex import I [as 别名]
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
示例4: extract
# 需要导入模块: import regex [as 别名]
# 或者: from regex import I [as 别名]
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)
示例5: _construct_regex
# 需要导入模块: import regex [as 别名]
# 或者: from regex import I [as 别名]
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)
示例6: search_citation
# 需要导入模块: import regex [as 别名]
# 或者: from regex import I [as 别名]
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