16

I'm looking for a good duplicate closure target for these questions:

Basically, the problem with constructing a RegExp by calling RegExp constructor, but forgetting to double up the backslashes. Solution is to double up the backslashes, or just use RegExp literal (if applicable).

Ideally, the answer should cover how to do it in both ways, explain why doubling up the backslashes (with examples covering several constructs in RegExp), and advise which to use in which cases.

Some candidates I currently have:

4
  • 6
    If you can come up with a reasonable example yourself, you could try to answer your own canonical. Perhaps others could give you feedback on what to include, or you could draft a sort of community wiki Q&A here and then post it on the main site.
    – ryanyuyu
    Oct 2, 2015 at 12:36
  • 2
    Oh, I really would like a canonical target for that.
    – Bergi
    Oct 2, 2015 at 22:58
  • I like Shouldn't this RegExp work? for its descriptive title :-) Apart from that, here's another list of questions that probably should get closed…
    – Bergi
    Oct 3, 2015 at 10:47
  • Interesting that this question exists, since I was about to ask a similar question about regualr expression in R where exactly the same issue plagues the "ordinary" regular expression resources. They don't handle the special or specific cases where a language also use the backslash to escape control characters. Makes me wonder if there's a canonical list of languages that have need of <esc><esc>
    – IRTFM
    Sep 20, 2019 at 0:24

0

You must log in to answer this question.

Browse other questions tagged .