[Israel.pm] RegEx question

Pinkhas Nisanov pinkhas at nisanov.com
Tue Mar 5 04:16:46 PST 2013


use look-ahead, e.g.:

my $str1 = "abc /* sdfkjhl";
my $str2 = "abc /* sdfkjhl */";

chkre( $str1 );
chkre( $str2 );

sub chkre {
  my ($str) = @_;
  if ($str =~ m|/\*(?!.*\*/)|)
    {
      print "MATCHED: $str\n";
    }
  else
    {
      print "DOES NOT MATCHED: $str\n";
    }
}

output:

MATCHED: abc /* sdfkjhl
DOES NOT MATCHED: abc /* sdfkjhl */


thanks
Pinkhas Nisanov



On Tue, Mar 5, 2013 at 1:20 PM, Yossi Itzkovich
<Yossi.Itzkovich at ecitele.com> wrote:
>
> Hi,
>
>
>
> I have a (simple) regex question that I don't remember how to do it
> efficiently:  I want to find all lines that have a starting of a C comment,
> but have no end of that comment at the rest of the line.
>
> For example:
>
>
>
> Abcdefg /* I want to match this line
>
> Abcdefg /* I don't want to match this line */
>
>
>
> How can it be done in one pattern ?
>
>
>
> Regards,
>
> Yossi
>
>
>
>
>
> This e-mail message is intended for the recipient only and contains
> information which is CONFIDENTIAL and which may be proprietary to ECI
> Telecom. If you have received this transmission in error, please inform us
> by e-mail, phone or fax, and then delete the original and all copies
> thereof.
>
>
> _______________________________________________
> Perl mailing list
> Perl at perl.org.il
> http://mail.perl.org.il/mailman/listinfo/perl


More information about the Perl mailing list