ure Character Class Issues

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
danp
Posts: 2
Joined: Sun Apr 22, 2018 6:36 pm

ure Character Class Issues

Post by danp » Sun Apr 22, 2018 7:20 pm

Hi folks,

I'm having trouble with some ure regex stuff. Specifically, escaping metacharacters.

This code works as expected - [ within [] is read as a literal.
>>> ure.search(r"[[]", "[")
<match num=2>

However, the following statements don't work (have tried multiple \ characters too):
>>> ure.search(r"[]]", "]")
>>> ure.search(r"[\]]", "]")

I've tried the following successfully using python 3 and re:
>>> re.search(r"[[]", "[")
<_sre.SRE_Match object; span=(0, 1), match='['>
>>> re.search(r"[\]]", "]")
<_sre.SRE_Match object; span=(0, 1), match=']'>

Ultimately, I want to use the following regex pattern (https://github.com/kanaka/mal/blob/mast ... -and-print), but I think I'm a way off yet:
[\s,]*(~@|[\[\]{}()'`~^@]|"(?:\\.|[^\\"])*"|;.*|[^\s\[\]{}('"`,;)]*)

Is this a limitation of ure, a bug, or am I simply just doing it wrong (very likely)?

Cheers in advance :)

Post Reply