Answer the question
In order to leave comments, you need to log in
How to construct a Regex from pieces of a string in python?
I have such substrings
and I want to get a regular expression of the form,
but I can’t figure out how to glue these lines together so that I can add an escape character \ before + td b"-"; b"|"; b"+"
rb"[\-|\||\+]+"
Answer the question
In order to leave comments, you need to log in
drive your substrings into an array and then join, map
arr = [b"-", b"|", b"+"];
print(rb'[' + b''.join(map(bytes, list(map(lambda e: b'\\'+e, arr))))+b']+')
# b'[\\-\\|\\+]'
rb"[\-|\||\+]+"
-|+
[|\-+]
[-|+]+
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question