Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] Help with some regular expressions

Expand Messages
  • David Precious
    On Fri, 09 Mar 2012 02:59:27 -0000 ... d is a character class matching digits ; {5,5} is a repetition range, matching between five and five repeats - so, it
    Message 1 of 3 , Mar 9, 2012
    • 0 Attachment
      On Fri, 09 Mar 2012 02:59:27 -0000
      "Tony" <GKillah36@...> wrote:

      > Can someone please tell me what these regular expressions do?
      >
      > 1.) /\d{5,5}/

      \d is a character class matching "digits"; {5,5} is a repetition range,
      matching between five and five repeats - so, it matches a series of
      five digits. It would be more normally written as /\d{5}/.

      > 2.) m/\w\w\w\w\w/

      \w is a character class matching word characters; it's repeated 5
      times, so it matches five word characters in a row. It would more
      normally be written as m/\w{5}/.

      > 3.) s/ //g

      This removes all spaces.

      E.g.:

      my $foo = "Foo bar baz";
      $foo =~ s/ //g;
      # $foo now contains "Foobarbaz";


      You're right that regexes are tricky to Google, but perlretut (the
      regular expressions tutorial from the Perl docs) will help you:

      http://perldoc.perl.org/perlretut.html

      Look in particular at "Using character classes" for more detailed
      explanations of what \d and \w match, and at "Matching repetitions" for
      a more detailed explanation of the range repetition quantifier.


      --
      David Precious ("bigpresh") <davidp@...>
      http://www.preshweb.co.uk/ www.preshweb.co.uk/twitter
      www.preshweb.co.uk/linkedin www.preshweb.co.uk/facebook
      www.preshweb.co.uk/cpan www.preshweb.co.uk/github
    • timothy adigun
      Hi Tony, ... d is a digit and represents [0-9], but not just [0-9] but also digits from non-roman scripts, while x{n,m} is for matching repetitions, i.e,
      Message 2 of 3 , Mar 9, 2012
      • 0 Attachment
        Hi Tony,

        On Fri, Mar 9, 2012 at 3:59 AM, Tony <GKillah36@...> wrote:

        > **
        >
        >
        > Hi all,
        >
        > Due to all the slashes and brackets and parentheses involved, it's a bit
        > of a hassle to Google this to get answers.
        >
        > Can someone please tell me what these regular expressions do?
        >
        > 1.) /\d{5,5}/
        >
        \d is a digit and represents [0-9], but not just [0-9] but also digits
        from non-roman scripts, while x{n,m} is for matching repetitions, i.e,
        match x, for atleast "n" number of times, but not more that "m" number of
        times.
        So, like David rightly pointed out, /\d{5}/, will be the correct thing to
        write, showing that you want to match extactly [0-9] "5" times. OR you can
        write /[0-9]{5}/

        >
        > 2.) m/\w\w\w\w\w/
        >
        \w is a word character (alphanumeric or _) and represents [0-9a-zA-Z_],
        but not just [0-9a-zA-Z_] but also digits and characters from non-roman
        script.

        >
        > 3.) s/ //g
        >
        This is using substitution operator to match spaces, and then remove them.

        Please, check:
        perldoc perlrequick
        perldoc perlretut


        >
        > Thank you!
        >
        > Tony
        >
        >
        >



        --
        Tim


        [Non-text portions of this message have been removed]
      Your message has been successfully submitted and would be delivered to recipients shortly.