Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Print strings based on regular expression

Reply
Thread Tools

Print strings based on regular expression

 
 
Yong Huang
Guest
Posts: n/a
 
      04-19-2009
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
 
Reply With Quote
 
 
 
 
Ted Zlatanov
Guest
Posts: n/a
 
      04-20-2009
On Sun, 19 Apr 2009 11:36:35 -0700 (PDT) Yong Huang <(E-Mail Removed)> wrote:

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
 
Reply With Quote
 
 
 
 
Yong Huang
Guest
Posts: n/a
 
      05-11-2009
On Apr 20, 1:58 pm, Ted Zlatanov <(E-Mail Removed)> wrote:
> On Sun, 19 Apr 2009 11:36:35 -0700 (PDT) Yong Huang <(E-Mail Removed)> wrote:
>
> 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/Reg...egexp/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
 
Reply With Quote
 
Ted Zlatanov
Guest
Posts: n/a
 
      05-12-2009
On Mon, 11 May 2009 14:56:37 -0700 (PDT) Yong Huang <(E-Mail Removed)> wrote:

YH> On Apr 20, 1:58 pm, Ted Zlatanov <(E-Mail Removed)> wrote:
>> On Sun, 19 Apr 2009 11:36:35 -0700 (PDT) Yong Huang <(E-Mail Removed)> wrote:
>>

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

>> 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.


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/Reg...egexp/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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
regular expression concatenation with strings oscartheduck Python 6 06-22-2007 10:44 PM
Strings, Strings and Damned Strings Ben C Programming 14 06-24-2006 05:09 AM
scan regular expression and strings STEPHEN BECKER I V Ruby 5 09-29-2004 04:02 PM
regular expression in strings David Bear Python 1 10-11-2003 02:47 AM
Dynamically changing the regular expression of Regular Expression validator VSK ASP .Net 2 08-24-2003 02:47 PM



Advertisments