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

Str.global_replace #8029

Closed
vicuna opened this issue Feb 24, 2003 · 2 comments
Closed

Str.global_replace #8029

vicuna opened this issue Feb 24, 2003 · 2 comments
Labels

Comments

@vicuna
Copy link

vicuna commented Feb 24, 2003

Original bug ID: 1558
Reporter: administrator
Status: closed
Resolution: not a bug
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)

Bug description

Full_Name: Alex Baretta
Version: 3.06
OS: Linux
Submission from: host108-4.pool62211.interbusiness.it (62.211.4.108)

let bs_regexp = "\\\\" (* Matches two BS in a row )
let bs_escape_tmpl = "\" (
We want to replace matching substrings
with one single BS*)

let text = "......"

let parsed_text = Str.global_replace bs_regexp bs_escape_tmpl text;;

---> Exception: Failure "Str.replace: illegal backslash sequence".

If I change the bs_escape_tmpl to "\\" I no longer get an exception, but
neither are my double-BS replaced by single BS--the "\\" template and the
"\\\\" regexp perform mutually trasformations on text.

Let me know...

Alex

@vicuna
Copy link
Author

vicuna commented Mar 10, 2003

Comment author: administrator

let bs_regexp = "\\\\" (* Matches two BS in a row )
let bs_escape_tmpl = "\" (
We want to replace matching substrings
with one single BS*)

let text = "......"

let parsed_text = Str.global_replace bs_regexp bs_escape_tmpl text;;

---> Exception: Failure "Str.replace: illegal backslash sequence".

Right: the replacement text for Str.global_replace can contain <digit>
sequences, hence a backslash character in the replacement text must be
escaped (\).

If I change the bs_escape_tmpl to "\\" I no longer get an exception, but
neither are my double-BS replaced by single BS--the "\\" template and the
"\\\\" regexp perform mutually trasformations on text.

This isn't what I observe here:

let re = Str.regexp "\\\\";;
let repl = "\\";;
let text = "This is some \\ text \\ with double backslashes\n";;
print_string text;;
(* Prints: This is some \ text \ with double backslashes )
print_string (Str.global_replace re repl text);;
(
Prints: This is some \ text \ with double backslashes *)

  • Xavier Leroy

@vicuna
Copy link
Author

vicuna commented Mar 10, 2003

Comment author: administrator

Can't reproduce problem.

@vicuna vicuna closed this as completed Mar 10, 2003
@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