match pattern *********

Discussion in 'Perl Misc' started by ela, Aug 3, 2008.

  1. ela

    ela Guest

    I wanna search a string "*********" and I remember some special characters
    can be used to tell the match so I need not type something like:

    \*\*\*\*...

    Would anybody know how to do that?
     
    ela, Aug 3, 2008
    #1
    1. Advertisements

  2. "ela" <> wrote:
    >I wanna search a string "*********" and I remember some special characters
    >can be used to tell the match so I need not type something like:
    >
    >\*\*\*\*...
    >
    >Would anybody know how to do that?


    See \Q in "perldoc perlre".

    jue
     
    Jürgen Exner, Aug 3, 2008
    #2
    1. Advertisements

  3. ela schrieb:

    > I wanna search a string "*********" and I remember some special characters
    > can be used to tell the match so I need not type something like:
    >
    > \*\*\*\*...



    (1) See jue's hint
    (2) use the ...{}-quantifier, eg.

    /\*{5}/

    to match exactly 5 asterisks, or

    /\*{2,7}/

    to match two up to seven of them.


    Again, read
    perldoc perlre



    hth + mfg,
    Hartmut

    --
    ------------------------------------------------
    Hartmut Camphausen h.camp[bei]textix[punkt]de
     
    Hartmut Camphausen, Aug 3, 2008
    #3
  4. Hartmut Camphausen <> wrote:

    > (2) use the ...{}-quantifier, eg.
    >
    > /\*{5}/
    >
    > to match exactly 5 asterisks, or



    Or, if you are backslash-averse as I am, you can write it as:

    /[*]{5}/


    --
    Tad McClellan
    email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
     
    Tad J McClellan, Aug 3, 2008
    #4
  5. Tad J McClellan wrote:
    > Hartmut Camphausen <> wrote:
    >
    >> (2) use the ...{}-quantifier, eg.
    >>
    >> /\*{5}/
    >>
    >> to match exactly 5 asterisks, or

    >
    >
    > Or, if you are backslash-averse as I am, you can write it as:
    >
    > /[*]{5}/


    Yes, but in Perl before 5.10 the backslashed version is more efficient.


    John
    --
    Perl isn't a toolbox, but a small machine shop where you
    can special-order certain sorts of tools at low cost and
    in short order. -- Larry Wall
     
    John W. Krahn, Aug 4, 2008
    #5
    1. Advertisements

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. RV
    Replies:
    1
    Views:
    555
    Donald 'Paddy' McCarthy
    Oct 23, 2003
  2. rk
    Replies:
    1
    Views:
    6,898
    Gunnar Hjalmarsson
    Dec 7, 2003
  3. hiwa
    Replies:
    0
    Views:
    808
  4. Victor
    Replies:
    2
    Views:
    806
    Victor
    May 17, 2004
  5. ekzept
    Replies:
    0
    Views:
    566
    ekzept
    Aug 10, 2007
  6. John Gordon
    Replies:
    13
    Views:
    742
    Ian Kelly
    Dec 20, 2011
  7. Volkan Civelek

    Match doesn't match

    Volkan Civelek, Jul 19, 2006, in forum: Ruby
    Replies:
    4
    Views:
    301
  8. Old Echo
    Replies:
    1
    Views:
    306
    Adam Shelly
    Sep 4, 2008
Loading...