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

Re: [PBML] Regex help

Expand Messages
  • Jenda Krynicky
    From: Malcolm Mill ... Try to read perlretut . Either run perldoc perlretut or go to
    Message 1 of 7 , Nov 3, 2004
      From: Malcolm Mill <malcolm.mill@...>
      > Hi Jenda,
      > The book I'm working from is "Apache, MySQL, and PHP Web Development:
      > For Dummies". It is a 7 books in 1 title, and has sections on Perl and
      > Regular Expressions. I looked for explicit examples of what I want to
      > to but couldnt find any so have been messing around with given
      > examples to try get the result I want.

      Try to read "perlretut".
      Either run
      perldoc perlretut
      or go to http://www.perldoc.com/perl5.8.4/pod/perlretut.html

      > > > print $_;
      > >
      > > If you are searching for something you should not mangle the data,
      > > just capture what do you need:
      > >
      > > /\t(\d{2}:\d{2})\s/ and print "$1\n";
      > >
      > >
      > > > }
      > >
      > This code, from another list does what I eventually wanted to do,
      > which was capture not only d2 numbers, but d1,2 and [ap]m.
      > foreach (<>) {
      > print "$1\n" while ($_ =~ /(\d{1,2}\:\d{2} [ap]m)/gi);
      > }
      > What exactly do { } and g do?

      The {} specifies that the number(s) within specify how many
      occurances of the previous character or group to match.

      > I understand \d{1,2} means capture digits of length 1 or 2. Why
      > couldnt I use [ ]? Are they only for characters?

      Inside [] most special characters are not special anymore. The []
      specifies a group of characters (a character class) that may be
      accepted at the current place. This means that
      means "match either a digit or 2" and is equivalent to
      is equivalent to
      that is it means "match an opening or closng curly or a comma or a

      Also /[:]/ is the same as /:/, /[\t]/ is the same as /\t/, /[\s]/ is
      the same as /\s/.

      So if I just simplified your regexp
      I'd get

      ===== Jenda@... === http://Jenda.Krynicky.cz =====
      When it comes to wine, women and song, wizards are allowed
      to get drunk and croon as much as they like.
      -- Terry Pratchett in Sourcery
    Your message has been successfully submitted and would be delivered to recipients shortly.