← index #7108Issue #5220
Related · high · value 2.162
QUERY · ISSUE

ure: character classes not working in sets

openby Gattagopened 2021-04-09updated 2024-09-13
enhancementextmod

All of these assert statements fail, but I don't think they should:

import ure
assert ure.match('[\\w]', "a") is not None
assert ure.match('[\\s]', " ") is not None
assert ure.match('[\\d]', "1") is not None
assert ure.match('[\\w.]*$', "boot.py") is not None
CANDIDATE · ISSUE

ure: escaped characters inside character classes not working

closedby andrewleechopened 2019-10-16updated 2019-10-20
extmod

This is similar and related to https://github.com/micropython/micropython/issues/3178

As per the above issue

>>> import ure
>>> print( ure.search(r"[a\-z]", "-") )
None
>>> print( ure.search(r"[a\-z]", "f") )
<match num=1>

escaping '-' inside character classes doesn't work, it still treats it as a range specifier. There is the workaround for that issue though by putting - at the start/end of the character class.

Similarly though, escaping ] also doesn't work, it appears to close the character class, but then there's the extra ] later on so you end up with an invalid regex.

>>> import ure
>>> print( ure.search(r"[a\]z]", "a") )
None

I don't think there's any way to make a character class that matches ']` at all.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied