Simple regex question

Discussion in 'Perl Misc' started by amirovic@googlemail.com, Feb 25, 2009.

  1. Guest

    Hi,

    I have a simple question but somehow I can't solve it myself:

    my $var = "[ a a a a a a a a ]";

    I'm working with Parse::Recdescent and would like to match this (it's
    not about Parse::Recdescent but a general question):

    rule: "[" /.*/ "]"

    Now "/.*/" matches everything including the "]", but I'd like to match
    every before "]". How should this be done?

    Thanks a lot for any response,
    Tom
     
    , Feb 25, 2009
    #1
    1. Advertising

  2. wrote:
    >
    > my $var = "[ a a a a a a a a ]";
    >
    > I'm working with Parse::Recdescent and would like to match this (it's
    > not about Parse::Recdescent but a general question):
    >
    > rule: "[" /.*/ "]"
    >
    > Now "/.*/" matches everything including the "]", but I'd like to match
    > every before "]". How should this be done?


    $var =~ /\[(.*)]/;
    print "\"$1\"\n";

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Feb 25, 2009
    #2
    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. Saad Malik
    Replies:
    5
    Views:
    387
    John C. Bollinger
    May 2, 2005
  2. John Salerno

    a simple regex question

    John Salerno, Apr 1, 2006, in forum: Python
    Replies:
    6
    Views:
    315
    Paddy
    Apr 2, 2006
  3. johnny

    Simple Python REGEX Question

    johnny, May 11, 2007, in forum: Python
    Replies:
    4
    Views:
    412
    James T. Dennis
    May 12, 2007
  4. Replies:
    3
    Views:
    773
    Reedick, Andrew
    Jul 1, 2008
  5. Sam Kong
    Replies:
    8
    Views:
    119
    Csaba Henk
    Mar 25, 2005
Loading...

Share This Page