I want to search string a
in string b = "sed s/xxx/[/"
Code:
a = "data sed s/xxx/[/"
b = r'\ssed s/xxx/[/\b'
re.findall(b,a)
Output Error
unexpected end of regular expression.
I want to search string a
in string b = "sed s/xxx/[/"
Code:
a = "data sed s/xxx/[/"
b = r'\ssed s/xxx/[/\b'
re.findall(b,a)
Output Error
unexpected end of regular expression.
The character [
is a regular-expression metacharacter. In order to match it literally, you need to escape it.
r'\ssed s/xxx/\[/' # backslash-escape it, or
r'\ssed s/xxx/[[]/' # put it in a character class
The second example also shows what the metacharacter is actually used for. In regular expressions, [abc]
matches a single character out of the enumeration (so either a
or b
or c
); this is called a character class.
Try
import re
a = "data sed s/xxx/[/"
b = r'\ssed s/xxx/\[/'
print re.findall(b,a)