6

How can I regex-escape a dynamically inputted string. I would like to surround it with actual regex code and then do matching, but I need all regex-special characters from the input escaped.

Richard Dally
  • 1,432
  • 2
  • 21
  • 38
Petr Skocik
  • 58,047
  • 6
  • 95
  • 142

1 Answers1

1

You can use raw string literal

string LitString = R"(^(?:[1-9]\d*?|0)?(?:\.(?:\d*?[1-9]|0))?(?<=[\d])$)";

doom87er
  • 458
  • 2
  • 8