From: hzhuo1 on
Hi,

I am a fresh man with python. I know there is regular expressions in
Python. What I need is that given a particular regular expression,
output all the matches. For example, given “[1|2|3]{2}” as the regular
expression, the program should output all 9 matches, i.e., "11 12 13
21 22 23 31 32 33".

Is there any well-written routine in Python or third-party program to
do this? If there isn't, could somebody make some suggestions on how
to write it myself?

Thanks.

Zhuo
From: Roy Smith on
In article
<ee2cfd35-3171-4ee7-ad3a-cf117e5527c5(a)r24g2000yqd.googlegroups.com>,
"hzhuo1(a)gmail.com" <hzhuo1(a)gmail.com> wrote:

> Hi,
>
> I am a fresh man with python. I know there is regular expressions in
> Python. What I need is that given a particular regular expression,
> output all the matches. For example, given �[1|2|3]{2}� as the regular
> expression, the program should output all 9 matches, i.e., "11 12 13
> 21 22 23 31 32 33".
>
> Is there any well-written routine in Python or third-party program to
> do this? If there isn't, could somebody make some suggestions on how
> to write it myself?
>
> Thanks.
>
> Zhuo

Please enumerate all the strings which match ".*". Use additional sheets
of paper if needed.
From: Ben Finney on
Roy Smith <roy(a)panix.com> writes:

> "hzhuo1(a)gmail.com" <hzhuo1(a)gmail.com> wrote:
> > What I need is that given a particular regular expression, output
> > all the matches.
[…]

> Please enumerate all the strings which match ".*". Use additional
> sheets of paper if needed.

+1 QOTW

--
\ “Are you pondering what I'm pondering?” “I think so, ... Brain, |
`\ but how can we get seven dwarves to shave their legs?” —_Pinky |
_o__) and The Brain_ |
Ben Finney
From: hzhuo1 on
Thanks for your reply.
So there isn't such a routine just because some of the regular
expressions cannot be enumerated. However, some of them can be
enumerated. I guess I have to write a function myself.

Zhuo

On Feb 6, 5:23 pm, Roy Smith <r...(a)panix.com> wrote:
> In article
> <ee2cfd35-3171-4ee7-ad3a-cf117e552...(a)r24g2000yqd.googlegroups.com>,
>
>
>
>
>
>  "hzh...(a)gmail.com" <hzh...(a)gmail.com> wrote:
> > Hi,
>
> > I am a fresh man with python. I know there is regular expressions in
> > Python. What I need is that given a particular regular expression,
> > output all the matches. For example, given ³[1|2|3]{2}² as the regular
> > expression, the program should output all 9 matches, i.e., "11 12 13
> > 21 22 23 31 32 33".
>
> > Is there any well-written routine in Python or third-party program to
> > do this? If there isn't, could somebody make some suggestions on how
> > to write it myself?
>
> > Thanks.
>
> > Zhuo
>
> Please enumerate all the strings which match ".*".  Use additional sheets
> of paper if needed.

From: Steven D'Aprano on
On Sat, 06 Feb 2010 16:05:15 -0800, hzhuo1(a)gmail.com wrote:

> Thanks for your reply.
> So there isn't such a routine just because some of the regular
> expressions cannot be enumerated. However, some of them can be
> enumerated. I guess I have to write a function myself.

How do you expect to tell the ones that can be enumerated apart from
those that can't be?

Regular expressions are programs in a "regex" programming language. What
you are asking for is the same as saying:

"Is there a program that can enumerate every possible set of data that is
usable as valid input for a given program?"

This, in turn, is equivalent to the Halting Problem -- if you can solve
one, you can solve the other. You might like to google on the Halting
Problem before you spend too much time on this.

(Note, however, it isn't necessary to solve the Halting Problem for *all*
cases in order to have a useful Endless Loop Detector program.)

Why do you think you need this? Seems to me you're starting on an
extraordinarily difficult job. I hope the benefit is equally
extraordinary.


[Aside: Python regexes aren't Turing Complete. I'm not sure about Perl
regexes. Either way, this might actually be less difficult than the
Halting Problem, as in "amazingly difficult" rather than "impossible".]


--
Steven
 |  Next  |  Last
Pages: 1 2 3 4 5
Prev: intolerant HTML parser
Next: how to fix bugs (python)