Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which special characters must be escaped when using Python regex module re?

I'm using the Python module re to write regular expressions for lexical analysis. I've been looking for a comprehensive list of which special characters must be escaped in order to be recognized by the regex to no avail. Can someone please point me to an exhaustive list?

The line in the current regex I'm writing that's giving me trouble is:

[\|\^&\+-%\*\/=!>]

I'd like it to recognize the characters: |^&+-%*/=!>

Have I not escaped something I should have?

like image 829
Victor Brunell Avatar asked Jan 11 '16 01:01

Victor Brunell


1 Answers

After the opening square bracket the only special characters are -, ^ and ]:

[|\^&+\-%*/=!>]

You can find the list of special characters here:

  • Regular Expression Syntax
  • python-regex-cheatsheet
like image 193
alecxe Avatar answered Oct 02 '22 17:10

alecxe