Hacker News new | ask | show | jobs
by hardwaregeek 1898 days ago
I don't know if this helpful, but from your description of your problem, here's how I'd do that in Rust:

- Use a regex to find a string in some text: use regexes, get a &str

- Escape all the regex reserved characters in that string: Okay this requires mutation but we can't mutate a &str, let's loop over the &str's characters (using the Chars iterator) and push them into a new String with the proper escapes

- The new String we own, so we can easily turn it into a regex and use it to search the original string.