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

\\2 in global_replace #3778

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

\\2 in global_replace #3778

vicuna opened this issue Aug 31, 2005 · 1 comment

Comments

@vicuna
Copy link

vicuna commented Aug 31, 2005

Original bug ID: 3778
Reporter: administrator
Status: acknowledged
Resolution: open
Priority: normal
Severity: feature
Category: otherlibs

Bug description

Full_Name: mattias waldau
Version: 3084
OS: WinXP
Submission from: c-328ae253.09-253-7570701.cust.bredbandsbolaget.se (83.226.138.50)

Got bitten by the \2 feature of global_replace. I had code that substitute in a
string from the user into a string and it contained \, i.e.

replace_first (String.regexp_string "{1}") "new_hire_training1\2" txt

and of course it failed. The solution is of course to use substitute_first
instead, i.e.

substitute_first arg1_regexp (fun _ -> "new_hire_training1\2") txt

Although this is of course a bit overkill for a simple search-replace.

Suggestion:

  1. Introduce a simple search-replace function that replace a substring with
    another substring without any use of regexp or templ

  2. Introduce a function quote_tmpl that quotes \ and mention it in the
    documentation of global_replace and substitute_first

@mshinwell
Copy link
Contributor

I'm afraid no-one has managed to implement this in the past 15 years. Given that there is a workaround (which actually isn't that uncommon -- I looked at Jane Street's re2 library and the interface was very similar in this regard), I'm closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants