Fix regex for bolding search terms (#865)
Updated regex to not remove chinese letters in bolding regexmain
parent
e99db8db26
commit
75682de892
|
@ -63,7 +63,7 @@ def bold_search_terms(response: str, query: str) -> BeautifulSoup:
|
||||||
if len(element) == len(target_word):
|
if len(element) == len(target_word):
|
||||||
return
|
return
|
||||||
|
|
||||||
if not re.match('.*[a-zA-Z0-9].*', target_word) or (
|
if re.match('.*[@_!#$%^&*()<>?/\|}{~:].*', target_word) or (
|
||||||
element.parent and element.parent.name == 'style'):
|
element.parent and element.parent.name == 'style'):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ def bold_search_terms(response: str, query: str) -> BeautifulSoup:
|
||||||
|
|
||||||
# Split all words out of query, grouping the ones wrapped in quotes
|
# Split all words out of query, grouping the ones wrapped in quotes
|
||||||
for word in re.split(r'\s+(?=[^"]*(?:"[^"]*"[^"]*)*$)', query):
|
for word in re.split(r'\s+(?=[^"]*(?:"[^"]*"[^"]*)*$)', query):
|
||||||
word = re.sub(r'[^A-Za-z0-9 ]+', '', word)
|
word = re.sub(r'[@_!#$%^&*()<>?/\|}{~:]+', '', word)
|
||||||
target = response.find_all(
|
target = response.find_all(
|
||||||
text=re.compile(r'' + re.escape(word), re.I))
|
text=re.compile(r'' + re.escape(word), re.I))
|
||||||
for nav_str in target:
|
for nav_str in target:
|
||||||
|
|
Loading…
Reference in New Issue