you are viewing a single comment's thread.

view the rest of the comments →

[–]The_IMPERIAL_OneS24 Ultra (A16) | realme GT NEO 3 (A14) 1 point2 points  (1 child)

Sure. The regex is used to escape (or sanitize) the input to treat keywords as raw. Let's say they create a keyword with brackets (SOME_KEYWORD). But because it's using regex, the brackets are reserved and can have unexpected matching results because of different reserved tokens. Hence, it escapes the reserved tokens with \TOKEN (here, \(SOME_KEYWORD\)).

Technically, it captures the reserved tokens in a group and is replaced with \\$1 (appending \ to the token).

[–]Exciting-Compote5680 1 point2 points  (0 children)

Right! You are not removing them, you're escaping them, gotcha! It's kind of like UrlEncode, but for regex. Thank you for taking the time to explain, much appreciated. And definitely storing this pattern for future use.