Maybe I am just too used to one way to do regular expressions. Admittedly, even doing them in PHP with ereg() and ereg_replace() (or, even, pereg() and pereg_replace()) feel clunky and clumsy. But, in Getting Started with Regular Expressions in .Net, this is their version of a regex:Dim SearchString As String = _
"A cobra is a very, very venomous snake!"
Dim Pattern As String = "\bve\w*"
Dim oMatch As Match
Dim MatchHits As Integer = 0
oMatch = Regex.Match(SearchString, _
Pattern, RegexOptions.IgnoreCase)
Do While oMatch.Success
MatchHits = MatchHits + 1
oMatch = oMatch.NextMatch()
If oMatch.Success Then
MessageBox.Show(oMatch.Value)
MessageBox.Show(oMatch.Index)
MessageBox.Show(oMatch.Length)
End If
Loop
It seems so much more natural in Perl (here is an overly terse implementation of the VB.Net code above translated):$_ = "A cobra is a very, very venomous snake!";
print join "\n", $&, $+[0] - length($&), length($&), "\n" while(/\bve\w*/g);
Even at maximum verbosity, the Perl "feels" cleaner:my $string = "A cobra is a very, very venomous snake!";
while($string =~ m/(\bve\w*)/g)
{
print $1, "\n";
print pos($string)-length($1), "\n";
print length($1), "\n";
}
J$
$a="A"and$'_="J";map{$a++}(66..ord
);$$_='$';print$'a,$$a
Comments