Regex with square brackets giving me an error /u/nimzobogo Python Education

I am trying to test if a line contains a string of text that contains an open square bracket, but when I use

headerrx = re.compile('^[Event ') 

it throws an error:

/filter_pgn.py:22: SyntaxWarning: invalid escape sequence '[' headerrx = re.compile('^[Event ') re.error: unterminated character set at position 1 

Any idea what I’m doing wrong? The text I’m trying to parse will look like:

[Event “name of event”]

submitted by /u/nimzobogo
[link] [comments]

​r/learnpython I am trying to test if a line contains a string of text that contains an open square bracket, but when I use headerrx = re.compile(‘^[Event ‘) it throws an error: /filter_pgn.py:22: SyntaxWarning: invalid escape sequence ‘[‘ headerrx = re.compile(‘^[Event ‘) re.error: unterminated character set at position 1 Any idea what I’m doing wrong? The text I’m trying to parse will look like: [Event “name of event”] submitted by /u/nimzobogo [link] [comments] 

I am trying to test if a line contains a string of text that contains an open square bracket, but when I use

headerrx = re.compile('^[Event ') 

it throws an error:

/filter_pgn.py:22: SyntaxWarning: invalid escape sequence '[' headerrx = re.compile('^[Event ') re.error: unterminated character set at position 1 

Any idea what I’m doing wrong? The text I’m trying to parse will look like:

[Event “name of event”]

submitted by /u/nimzobogo
[link] [comments] 

Leave a Reply

Your email address will not be published. Required fields are marked *