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

Regex help - 1 of 2 things NOT BOTH

Expand Messages
  • Susan James
    email@domain.com,new_zealand,confirm-subscribe-bvximqypbczcck-new_zealand@domain.com,rpqbvpymsgxpgpfzdboyjmvgggvzfifwkbkacmqexsuieujujxodeqyhtdqlfexua,10546428
    Message 1 of 3 , Jun 3, 2003
    • 0 Attachment
      email@...,new_zealand,confirm-subscribe-bvximqypbczcck-new_zealand@...,rpqbvpymsgxpgpfzdboyjmvgggvzfifwkbkacmqexsuieujujxodeqyhtdqlfexua,1054642827


      Hi there...

      Im finding this a big difficult - Ive got a line with a few random
      characters in it..

      I was wondering - Is there a simple regex that can remove the SECOND
      domain name only (I want to keep the first one..

      $gotline =~ s/(\@...)?.*$//i;

      Ive got the above regex, However Im not quite sure where to put the ?
      (question mark)

      Ive seen it used a few times - but never used it.. - The tests ive done
      have removed ALL the line (nothing left) - done nothing, or removed both
      domain names

      Am I on the right track ? or would I need to split, & eliminate the domain
      name - & re-do the line.. - in 2-3 steps ?
      ( I can do that, but i'll rather learn regex power )

      Sue


      [Non-text portions of this message have been removed]
    • Gerd Ewald
      Good afternoon Susan, On Wed, 04 Jun 2003 01:00:00 +1200 GMT your local time, which was 03.06.2003, 15:00 (GMT+0200) where I live, you (Susan James) ... Well,
      Message 2 of 3 , Jun 3, 2003
      • 0 Attachment
        Good afternoon Susan,


        On Wed, 04 Jun 2003 01:00:00 +1200 GMT your local time,
        which was 03.06.2003, 15:00 (GMT+0200) where I live, you (Susan James)
        wrote in mid:5.2.0.9.0.20030604005155.00a90ec0@...:


        > $gotline =~ s/(\@...)?.*$//i;

        Well, you replace the matched string by nothing. That's why everything
        is deleted.

        Without knowing your special problem I would recommend the following:

        $gotline =~ s/(\@...).*(.*\@.*?)$/$2/;

        But I don't know your special problem, so this might be wrong in your
        case :-/

        <advertising>
        Anyway, if you like to learn more about regex, I would like to
        redirect you to a tutorial I wrote on "Using Regular Expressions"
        Go to http://www.regenechsen.de/regex_en/regex_1_en.html It is in
        English and there is a PDF for download available
        </advertising>


        --
        Best regards,
        Gerd
        =======================================================
        Tutorial for using regular expressions with TheBat! www.regenechsen.de
        -------------------------------------------------------
        Windows message: "Error saving file! Format drive now? (Y/Y)"
        -------------------------------------------------------
      • Jonathan Dunn
        On Wed, 04 Jun 2003 01:00:00 +1200, Susan James wrote ... Susan - this might be a start ... not a very complex regex for the email or domain or whatever you re
        Message 3 of 3 , Jun 3, 2003
        • 0 Attachment
          On Wed, 04 Jun 2003 01:00:00 +1200, Susan James wrote
          > email@...,new_zealand,confirm-subscribe-bvximqypbczcck-
          > new_zealand@...,
          > rpqbvpymsgxpgpfzdboyjmvgggvzfifwkbkacmqexsuieujujxodeqyhtdqlfexua,
          > 1054642827
          >
          >
          > Hi there...
          >
          > Im finding this a big difficult - Ive got a line with a few random
          > characters in it..

          Susan - this might be a start ... not a very complex regex for the email or
          domain or whatever you're trying to get ...

          ### script

          #!/usr/local/bin/perl

          use CGI qw( :standard ) ;
          use CGI::Carp qw( fatalsToBrowser ) ;
          use strict ;

          print header ;
          print start_html ;
          print "<pre>\n" ;
          print "Starting:\n\n" ;

          my $emailaddy = q([\w\.\-\_]+\@\w+(?:\.\w+)+) ; # or whatever good def'n

          my $string = q[email@...,new_zealand,confirm-subscribe-bvximqypbczcck-
          new_zealand@...,rpqbvpymsgxpgpfzdboyjmvgggvzfifwkbkacmqexsuieujujxodeqy
          htdqlfexua,1054642827] ;

          print "before, string is $string\n" ;

          $string =~ s#^(.*?${emailaddy}.*?)($emailaddy)(.*)$#\1\3# ;

          print " after, string is $string\n" ;

          print "\nFinished\n" ;
          print end_html ;
          close ;
          exit ;
        Your message has been successfully submitted and would be delivered to recipients shortly.