I am trying to convert a Perl script to a C# 3.5 routine.
The perl code I have is:
if($work =~ /\<[0-9][0-9][0-9]\>/){
$left = $`;
$match = $&;
$work = $';
}
In C# I wrote the following code:
string[] sSplit = Regex.Split(work, @"\<[0-9][0-9][0-9]\>");
if sSplit.length is > 2
{
left = sSplit[0];
match = sSplit[1];
work = sSPlit[2];
}
However the above is not giving me the matched pattern in sSplit[1], but the content to the right of the matched string instead.
Regex.Splitis not what you need. The equivalent to=~ /.../isRegex.Match.However,
Regex.Matchhas no equivalent to Perl’s$`or$', so you need to use a workaround, but I think it’s a fair one:Alternatively, you can use the match index and length to get the stuff: