Print strings based on regular expression

Y

Yong Huang

Is there a program that prints all possible strings based on a regular
expression?

$ thisprogram '^\w\d$'
A0
A1
....
z9

The output could easily be made infinite. That's fine. The point is to
let users visualize what the matching strings look like. I think this
program has great educational value in teaching regular expressions.

Yong Huang
 
T

Ted Zlatanov

YH> Is there a program that prints all possible strings based on a regular
YH> expression?

YH> $ thisprogram '^\w\d$'
YH> A0
YH> A1
YH> ...
YH> z9

YH> The output could easily be made infinite. That's fine. The point is to
YH> let users visualize what the matching strings look like. I think this
YH> program has great educational value in teaching regular expressions.

See _Higher-Order Perl_ by Mark-Jason Dominus, chapter 6.5 (generating a
list of all the strings matched by a regular expression). The whole
book is terrific.

It's available online for free but it's also one of the few Perl books I
recommend purchasing without reservation.

Ted
 
Y

Yong Huang

YH> Is there a program that prints all possible strings based on a regular
YH> expression?

YH> $ thisprogram '^\w\d$'
YH> A0
YH> A1
YH> ...
YH> z9

YH> The output could easily be made infinite. That's fine. The point is to
YH> let users visualize what the matching strings look like. I think this
YH> program has great educational value in teaching regular expressions.

See _Higher-Order Perl_ by Mark-Jason Dominus, chapter 6.5 (generating a
list of all the strings matched by a regular expression). The whole
book is terrific.

It's available online for free but it's also one of the few Perl books I
recommend purchasing without reservation.

Ted

Thanks, Ted. After hours of testing the functions in that excellent
book, I searched CPAN one more time and found

http://search.cpan.org/~bowmanbs/Regexp-Genex-0.07/lib/Regexp/Genex.pm

It's much easier to use. But currently it doesn't output all possible
characters given character class or \w or \d (or I didn't get it to
work). Every time it picks one but different character to output.
Anyway, it's close to what I want.

Yong Huang
 
T

Ted Zlatanov

YH> Is there a program that prints all possible strings based on a regular
YH> expression?

YH> Thanks, Ted. After hours of testing the functions in that excellent
YH> book, I searched CPAN one more time and found

YH> http://search.cpan.org/~bowmanbs/Regexp-Genex-0.07/lib/Regexp/Genex.pm

YH> It's much easier to use. But currently it doesn't output all possible
YH> characters given character class or \w or \d (or I didn't get it to
YH> work). Every time it picks one but different character to output.
YH> Anyway, it's close to what I want.

Cool, I'm glad you found something you like, and I didn't know about
Regexp::Genex.

Ted
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top