looking for some solutions? You are welcome.

SOLVED: Regex Character Class [-/] works but [/-] does not

Anand Rayudu:
  1. Please explain as to why the first character class is working, but not the second one

This does work :

p = re.compile("\d\d[.-/ ]\d\d[.-/ ]\d\d\d\d")`

This does not work :

p = re.compile("\d\d[./- ]\d\d[./- ]\d\d\d\d")

Traceback (most recent call last):

  File "C:/pyprg/prac01.py", line 2, in <module>
        p = re.compile("\d\d[./- ]\d\d[./- ]\d\d\d\d")   File "C:\Python361\lib\re.py", line 233, in compile
        return _compile(pattern, flags)   File "C:\Python361\lib\re.py", line 301, in _compile
        p = sre_compile.compile(pattern, flags)   File "C:\Python361\lib\sre_compile.py", line 562, in compile
        p = sre_parse.parse(p, flags)   File "C:\Python361\lib\sre_parse.py", line 856, in parse
        p = _parse_sub(source, pattern, flags & SRE_FLAG_VERBOSE, False)   File "C:\Python361\lib\sre_parse.py", line 415, in _parse_sub
        itemsappend(_parse(source, state, verbose))   File "C:\Python361\lib\sre_parse.py", line 552, in _parse
        raise source.error(msg, len(this) + 1 + len(that)) sre_constants.error: bad character range /-  at position 6

Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered

No comments: