Regex and dynamic text. A tiny cautionary tale

I use regex operators a lot. Like a LOT. It pretty much is my go-to for all my complex filtering and searching solutions. It runs extremely fast and extremely flexible since it takes dynamic expressions. I use it for the detecting conditionals in the form builders in my Bubble apps.

Anyway the point of this post is to remind myself and any who read this to always remember to escape special characters in your regex expressions. After so many uses I still forget this every once in a while.

How? Would be helpful to see.

The easiest and fastest way I found was use to Toolbox’s expression element to do the conversion using JS.

image

image

ChatGPT never forgets :laughing:

It would be good if Bubble.io supported \Q and \E in order to pass strings as is.

Thank you thank you thank you … this has been driving me crazy until I read your post … thank you! Bit more from my AI research that found your post …

A simple find replace of the below does the trick - in that order, i.e. replace \ before /

\ -> \\
/ -> \/
. -> \.
* -> \*
+ -> \+
? -> \?
^ -> \^
$ -> \$
( -> \(
) -> \)
[ -> \[
] -> \]
{ -> \{
} -> \}
| -> \|