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

Re: [PBML] Correct pattern Matching

Expand Messages
  • Tom Barron
    This works for me: $line = 00/07/31 now is the time ; ($date) = ($line =~ m|( d{2}/ d{2}/ d{2}).*|); print date = $date n ; I think the problem with your
    Message 1 of 1 , Aug 1, 2000
      This works for me:

      $line = "00/07/31 now is the time";
      ($date) = ($line =~ m|(\d{2}/\d{2}/\d{2}).*|);
      print "date = '$date'\n";

      I think the problem with your code was 1) the first '/' inside your
      regexp terminated it. You need a different delimiter if the regexp
      contains '/'. And 2) you weren't putting your scalar inside parens.
      Since the ($var =~ /regexp/) returns a list, you need to put the scalar
      to receive the value in a list.


      > I am having a problem with pattern matching. The script I am using
      > parses a line of a log file and extracts the date, time and ip
      > address. My problem is in the regular expression I am using. For
      > example, I use @startDate = ($line1 =~ /(\d{2}\/\d{2}\/\d{2})/g) to
      > match the date. Notice I am using an array rather than a scalar
      > variable because it only grabs one piece at a time. If I use a scalar
      > variable I'll simply get one digit. Storing the in an array does not
      > suit my needs as I have to do mathmatical calculations using the dates
      > and times. My question is how can I change the regular expression so
      > that it returns the full date (in 01/22/00 format) at one time, so I
      > can store it in a scalar vaiable. Thanks in advance,
      > --Jason Sperry
      > http://bjorkradio.yi.org
      > The Internet's only all Bjork Radio Station
      > ----------------------------------------------------------------------
      > ----------------------------------------------------------------------
    Your message has been successfully submitted and would be delivered to recipients shortly.