Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String_match on multi-line strings #3569

Closed
vicuna opened this issue Mar 31, 2005 · 1 comment
Closed

String_match on multi-line strings #3569

vicuna opened this issue Mar 31, 2005 · 1 comment
Labels

Comments

@vicuna
Copy link

vicuna commented Mar 31, 2005

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

@vicuna
Copy link
Author

vicuna commented Apr 17, 2005

Comment author: administrator

Behavior is as documented: " . matches any character except newline".

@vicuna vicuna closed this as completed Apr 17, 2005
@vicuna vicuna added the bug label Mar 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant