[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Help with RegEx



At 16:24 +0100 11/12/00, Greenblatt & Seay wrote:
>  if ($test =~ /(..)\/(..)\/(..)/) {
>      $date = "$1\/$2\/$3";
>      print $date;

Or, one can reduce the LTS* problem a little by using the fuller form of
the match regular expression syntax (for a longer RE it would be more
obviously useful):

#!perl -w

  $test = <<"EOF";
I have to extract dates from a text, store them into an array and then use
AppleScript to save them into a FileMaker Pro database.
The dates in the text are in the following format: mm/dd/yy.

I have tried some expressions, but since I am not experienced, Perl returns
the entire line that contains the date.

If you can help, please let me know.
EOF


  if ($test =~ m*(..)/(..)/(..)*) {
      $date = "$1\/$2\/$3";
      print $date;
  }

__END__


* "LTS":  Leaning Toothpick Syndrome

You have a lot of freedom with the delimiters...since [ and ] aren't in the
RE, one could also nicely use
    m[(..)/(..)/(..)]
(note that the delimiters are a pair in the "right" choices of delimiter).

   --John
-- 
John Baxter   jwblist@olympus.net      Port Ludlow, WA, USA

# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org