You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Original bug ID: 3569 Reporter: administrator Status: closed Resolution: not a bug Priority: normal Severity: minor Category: ~DO NOT USE (was: OCaml general)
The Str.string_match function and the Str.global_replace don't work the same
way.
The Str.string_match function only tests on the first line inside the string.
The Str.global_replace function replaces words in all the lines inside the
string.
In the normal regular expression implementations like preg it is possible to
indicate if the search should be over more than one line or on a single line.
But without such an option in the library I thing multiple lines should be the
default.
At least the manual should state that only the first line in a string is
tested.
The next example program illustrates the difference in handling multi-line
strings.
match.ml:
let match_it s=
print_string ("Testing: '" ^ s ^ "'\n");
print_string ("Replace: '" ^ Str.global_replace (Str.regexp "test") "string" s ^
"'\n");
if Str.string_match (Str.regexp ".test") s 0 then
print_string "Matched\n" else print_string "Error\n";
if Str.string_match (Str.regexp ".\n.*test") s 0 then
print_string "Alternative\n";
print_string "\n"
;;
match_it "This is the first test";
match_it "This is a\nsecond test"
This is run with:
ocaml /usr/lib/ocaml/3.08.3/str.cma match.ml
And the result at my system was:
Testing: 'This is the first test'
Replace: 'This is the first string'
Matched
Testing: 'This is a
second test'
Replace: 'This is a
second string'
Error
Alternative
The text was updated successfully, but these errors were encountered:
Original bug ID: 3569
Reporter: administrator
Status: closed
Resolution: not a bug
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)
Bug description
Full_Name: Jurjen Stellingwerff
Version: ocaml 3.08.3
OS: debian linux unstable
Submission from: ullivarra.demon.nl (82.161.51.70)
The Str.string_match function and the Str.global_replace don't work the same
way.
The Str.string_match function only tests on the first line inside the string.
The Str.global_replace function replaces words in all the lines inside the
string.
In the normal regular expression implementations like preg it is possible to
indicate if the search should be over more than one line or on a single line.
But without such an option in the library I thing multiple lines should be the
default.
At least the manual should state that only the first line in a string is
tested.
The next example program illustrates the difference in handling multi-line
strings.
match.ml:
let match_it s=
print_string ("Testing: '" ^ s ^ "'\n");
print_string ("Replace: '" ^ Str.global_replace (Str.regexp "test") "string" s ^
"'\n");
if Str.string_match (Str.regexp ".test") s 0 then
print_string "Matched\n" else print_string "Error\n";
if Str.string_match (Str.regexp ".\n.*test") s 0 then
print_string "Alternative\n";
print_string "\n"
;;
match_it "This is the first test";
match_it "This is a\nsecond test"
This is run with:
ocaml /usr/lib/ocaml/3.08.3/str.cma match.ml
And the result at my system was:
Testing: 'This is the first test'
Replace: 'This is the first string'
Matched
Testing: 'This is a
second test'
Replace: 'This is a
second string'
Error
Alternative
The text was updated successfully, but these errors were encountered: