HP Forums
Python ure (regular expressions) functionality - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: Python ure (regular expressions) functionality (/thread-19781.html)



Python ure (regular expressions) functionality - dmh - 04-07-2023 01:51 AM

I'm trying to use the Prime Python ure library but its functionality appears to be quite limited.

Firstly, compile appears to work but the compiled expression can't be used and just generates an error so I'm not using the compile function directly.

Search appears to work with expressions, however, there appears to be no way to retrieve the match as there is no group, start or end functions etc.

I also note that match returns None on no match or 1 on a match or 2 if the search includes grouping as shown below. What is this result indicating and why is it different for both matches?

Code:
import ure
match=ure.search("a.a","1234axa5678")
match
<match num=1>

match=ure.search("(a.a)","1234axa5678")
match
<match num=2>

Is there anyway to retrieve the match result?

I note that some MicroPython functions depend on the port but this is not mentioned for group() but then I don't know what version of MicroPython was used in the Prime.

Also, given the documentation on Python functions is brief, is there anyway to list all the attributes/functions of a class? dir() just returns 'class'.

Hopefully there's a simple fix for this or I'm doing something wrong.

I've tried this on the latest firmware on a G2 and on the virtual Prime.

Thanks, dmh