Print strings based on regular expression

Discussion in 'Perl Misc' started by Yong Huang, Apr 19, 2009.

  1. Yong Huang

    Yong Huang Guest

    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
     
    Yong Huang, Apr 19, 2009
    #1
    1. Advertising

  2. Yong Huang

    Ted Zlatanov Guest

    On Sun, 19 Apr 2009 11:36:35 -0700 (PDT) Yong Huang <> 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
     
    Ted Zlatanov, Apr 20, 2009
    #2
    1. Advertising

  3. Yong Huang

    Yong Huang Guest

    On Apr 20, 1:58 pm, Ted Zlatanov <> wrote:
    > On Sun, 19 Apr 2009 11:36:35 -0700 (PDT) Yong Huang <> 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/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
     
    Yong Huang, May 11, 2009
    #3
  4. Yong Huang

    Ted Zlatanov Guest

    On Mon, 11 May 2009 14:56:37 -0700 (PDT) Yong Huang <> wrote:

    YH> On Apr 20, 1:58 pm, Ted Zlatanov <> wrote:
    >> On Sun, 19 Apr 2009 11:36:35 -0700 (PDT) Yong Huang <> 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/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
     
    Ted Zlatanov, May 12, 2009
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. VSK
    Replies:
    2
    Views:
    2,305
  2. David Bear

    regular expression in strings

    David Bear, Oct 11, 2003, in forum: Python
    Replies:
    1
    Views:
    299
    David M. Cooke
    Oct 11, 2003
  3. Ben

    Strings, Strings and Damned Strings

    Ben, Jun 22, 2006, in forum: C Programming
    Replies:
    14
    Views:
    767
    Malcolm
    Jun 24, 2006
  4. keto
    Replies:
    0
    Views:
    964
  5. David Cournapeau

    print a vs print '%s' % a vs print '%f' a

    David Cournapeau, Dec 30, 2008, in forum: Python
    Replies:
    0
    Views:
    363
    David Cournapeau
    Dec 30, 2008
Loading...

Share This Page