The following warnings occurred:
Warning [2] count(): Parameter must be an array or an object that implements Countable - Line: 795 - File: showthread.php PHP 7.4.33 (FreeBSD)
File Line Function
/showthread.php 795 errorHandler->error





Post Reply 
Python ure (regular expressions) functionality
04-07-2023, 01:51 AM
Post: #1
Python ure (regular expressions) functionality
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

Calculator Clique on YouTube
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


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



User(s) browsing this thread: 1 Guest(s)