Gossamer Forum
Home : General : Perl Programming :

Regex again.

Quote Reply
Regex again.
my $count;
my $description = "This is my description and it contains numerous __ double underscore marks and __ these mark some special area in the
field";

$count++ while $description =~ /(__)/gi;

############
The above code will give 1 if __ is found in the description 2 if __ and __ found in the field and so on.

My problem is I want to get the same result even upto six under scores in a row. i.e.

______ (six underscores in a row or less) should equal one. (1-6 underscores should equal one).

Any ideas?

Last edited by:

zeshan: Jul 9, 2003, 6:20 PM
Quote Reply
Re: [zeshan] Regex again. In reply to
How about:

$count++ while $description =~ /_{1,6}/g;

----
Cheers,

Dan
Founder and CEO

LionsGate Creative
GoodPassRobot
Magelln
Quote Reply
Re: [zeshan] Regex again. In reply to
$count++ while $description =~ /_+/g;

if you want one or more to equal 1

$count++ while $string =~ /_{2,}/g;

if you want two or more to equal 1
Quote Reply
Re: [adrockjames] Regex again. In reply to
But he said 1-6 so Dan's answer is correct =)
Quote Reply
Re: [Paul] Regex again. In reply to
oh, sorry. thought he was using 6 as an example, not as a hard stop :)
Quote Reply
Re: [adrockjames] Regex again. In reply to
Maybe a better way than incrementing a counter would be:

Code:
my $count = $string =~ s/_{1,6}//g;