I
I
Ivan Yakushenko2020-05-30 17:06:44
Python
Ivan Yakushenko, 2020-05-30 17:06:44

How to insert a line with spec. characters in a regular expression?

There is a need to dynamically create regular expressions to search for substrings with different headers, it looks something like this:

event_bc = re.search(r'NA={};.+?BC=(.+?);'.format(event_title), category_block)

The problem is that event_title can have specials. symbols. Now it's all implemented by an extremely poor replacement of specials. characters per line:
spec_symbs = ('(', ')')
for sym in spec_symbs:
    event_title = event_title.replace(sym, f'\\{sym}')

There is a way to insert a line with ignoring specials. characters in the regular expression itself?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
galaxy, 2020-05-30
@kshnkvn

re.escape()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question