In port of a perl application to dart, I have to deal with regular expressions of the form below. The result of of the execution of both perl version and Dart version is included. The idea is simple replace basic patterns at the end of string. For me, the result that I get from perl fragment is correct. However the results from Dart version does not seem right. I would appreciate your help to understand where am I going wrong. Thanks in advance.
my $str ="this is a line of text ‖ ###";
print("\nIn 1 str=|$str|");
$str =~ s/###$/\n/g;
print("\nIn 2 str=|$str|");
$str =~ s/ ‖ $//g;
print("\nIn 3 str=|$str|");
output:
In 1 str=|this is a line of text ‖ ###|
In 2 str=|this is a line of text ‖
|
In 3 str=|this is a line of text
|
Dart code:
void main() {
var str;
str ="this is a line of text ‖ ###";
print("\nIn 1 str=|$str|");
str = str.replaceAll(RegExp(r'###$'), "\n");
print("\nIn 2 str=|$str|");
str = str.replaceAll(RegExp(r' ‖ $'), "");
print("\nIn 3 str=|$str|");
print("\n\n");
}
output:
In 1 str=|this is a line of text ‖ ###|
In 2 str=|this is a line of text ‖
|
In 3 str=|this is a line of text ‖
|
As you see:
str = str.replaceAll(RegExp(r' ‖ $'), "");
does not replace the pattern ' ‖ $' with "" as opposed to its perl equivalent.