Unable to use regex expression #10299
-
I have search the webz and I think maybe the problem is string escaping but I am not 100% sure since is working in python3.10 just fine. I have read some posts about another RE library for micropython but I was unable to figure out how to install it with mip (re-pcre) maybe it doesn't exists anymore. https://forum.micropython.org/viewtopic.php?t=5398 I have strings like this where it should match square brackets:
array_pattern = re.compile('\[([\d]|[,]|[\s])*\]')
index = array_pattern.search(tag).group(0) Can anyone point me into what I am doing wrong. Running micropython v1.19 latest on main branch unix port. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 9 replies
-
MicroPython's [u]re module is very small. The re-pcre module is old and is no longer in micropython-lib. MicroPython is a subset of an older Python than 3.10. What are you looking for? |
Beta Was this translation helpful? Give feedback.
-
For users seeking unofficial libraries see awesome micropython. |
Beta Was this translation helpful? Give feedback.
-
@TheFern2 Sorry about the delay responding... The issue here is that Python supports using named character classes (e.g. You've used |
Beta Was this translation helpful? Give feedback.
MicroPython's [u]re module is very small. The re-pcre module is old and is no longer in micropython-lib. MicroPython is a subset of an older Python than 3.10.
What are you looking for?
\[.+\]
will match square bracket groups (or\[[^\]]+\]
if you're cautious). I don't think we have PCRE's pipe matching at all.