help with reg ex

S

Sunil

Hi,
I have a pattern matching program which acts on a multi-line string.
This works fine for me.
But I need to ignore matches in lines that start with a '-' or '#' which
is like a comment line and need not be checked.
Any easy way of doing this?. Since I have a multi-line string variable
I would like to avoid line by line processing.

Thanks,
Sunil.
 
B

Ben Morrow

Sunil said:
I have a pattern matching program which acts on a multi-line string.
This works fine for me.
But I need to ignore matches in lines that start with a '-' or '#' which
is like a comment line and need not be checked.
Any easy way of doing this?. Since I have a multi-line string variable
I would like to avoid line by line processing.

(my $new = $old) =~ s/[-#].*?\n//;

Then match against $new instead.
 
T

Tad McClellan

Ben Morrow said:
I need to ignore matches in lines that start with a '-' or '#'
^^^^^^^^^^

(my $new = $old) =~ s/[-#].*?\n//;

Then match against $new instead.


Need an anchor and "mg" options.

Don't need non-greedy (since there is no "s" option).

(my $new = $old) =~ s/^[-#].*\n//mg;

or maybe:

(my $new = $old) =~ s/^\s*[-#].*\n//mg;
 
E

Eric J. Roode

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,
I have a pattern matching program which acts on a multi-line
string.
This works fine for me.
But I need to ignore matches in lines that start with a '-' or '#'
which
is like a comment line and need not be checked.
Any easy way of doing this?. Since I have a multi-line string
variable
I would like to avoid line by line processing.

Use two expressions:

if (!/[^#-]/ && /your working regex/)
{
...do your thing...
}

- --
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBP8ddFmPeouIeTNHoEQINpgCbBITNpt+f+FelVgcgRYJt6NqOAbgAn1W6
xZLnDPLE+CVaUDzhb/w98RVL
=gWvq
-----END PGP SIGNATURE-----
 
B

Ben Morrow

Need an anchor and "mg" options.

Don't need non-greedy (since there is no "s" option).

(my $new = $old) =~ s/^[-#].*\n//mg;

or maybe:

(my $new = $old) =~ s/^\s*[-#].*\n//mg;

Sorry, yes.

Ben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,266
Messages
2,571,082
Members
48,773
Latest member
Kaybee

Latest Threads

Top