[Tutor] Using Regex to produce text
mhw at doctors.net.uk
mhw at doctors.net.uk
Wed Apr 28 17:32:38 CEST 2010
While some patterns are infinite, other's aren't (e.g. The example I gave).
Using a subset of Regex syntax to produce a set of strings has the advantage of using a well understood and documented form, and if you could hook into the existing API, at minimal coding effort.
In addition, it allows a nice symmetry between search and production of resource names.
E.g.
Source some data (containing resources)
Label res 1 to res n using re.pattern(p1)
Add this data to the larger data lump
.... do some stuff...
Find the data items you had again:
DataGroup1 = AllData.search(re.pattern(p1))
I suspect it's not that easy, as I don't think we can get to the internals of the regex FSM. However, I thought it would be worth asking.
Matt
Etc.
------Original Message------
From: Luke Paireepinart
To: mhw at doctors.net.uk
Cc: Python tutor
Subject: Re: [Tutor] Using Regex to produce text
Sent: 28 Apr 2010 07:51
On Wed, Apr 28, 2010 at 1:27 AM, <mhw at doctors.net.uk> wrote:
> Dear All,
>
> Quick question:
>
> Is there an way of using the regex patterns to produce text, instead of matching it?
>
> E.g.:
> pat = re.compile("ab?d")
> pat.getListofPossibleText()
>
There's no end to the length of many patterns so this would be fairly pointless.
For example, what would getListofPossibleText do for the pattern ".*" ?
I think the better question is: what are you trying to do?
Or perhaps: Why do you think you need to solve your problem this way?
-Luke
Sent from my BlackBerry® wireless device
More information about the Tutor
mailing list