Case-Insensitive Regex in Bubble

I want to do a find and replace using a fairly simple word boundary Regex pattern, but I need it to be case-sensitive.

From @emmanuel in another thread:

Behind the scene we do this
regex = new RegExp(find, ‘g’)
so find should be what you put there.

It seems that I want is a way to specify ‘gi’ instead of just ‘g’, but not sure how to accomplish that in Bubble. I kinda worked around it by setting up multiple conditions using :capitalized words and :uppercase, but those aren’t really foolproof for my project.

1 Like

To ignore the case on the action of the expression, you would need to do the [A-Za-z]

Edit: The i flag does relate to turning off case sensitivity. Removed my original comment to remove any potential confusion!

Not sure. But I should have clarified that the string of my word boundary pattern is dynamically pulled from the database.

Have you tried modify the regex pattern to deal with the case element, i.e. [A-Za-z] in the pattern.

if bubble where to modify the what is in the background to ignorecase (i flag, if that is what it is for), then those to do not want to ignore case would be affected.

I think the case sensitivity should reside in the expression.

Apologies in advance if I’m speaking poop, but it has been a very loooong time since I did any heavy regex stuff!

I guess I’m wondering if Bubble can/should expose an optional case-insensitive setting (making it a “gi” find) or if there is some other way to specify that in the pattern input. Putting (?i) in the pattern expression doesn’t seem to work.

1 Like

That’s what the [A-Za-z] token does, in this case match upper case or lowercase character in the range Aa to Zz. So [A-Z] will not match the same as [a-z],

Try it out at this online test site:
http://www.regextester.com/

Thanks – had not used regextester.com before, so that’s a nice find.

Still not sure where to put that token, though. Let’s say I want to find a match of the case-insensitive string hello with word boundary.

The regex pattern is simply \bhello\b … where does that [A-Za-z] token go?

Notice also that on regextester.com, they have a little section where you can select the flags that you want. By default, it is set to global (g) but you can optionally add case-insensitive (i) as a flag. That’s kinda what I would like to have here.

1 Like

That isn’t an explicit token as such, it is a pattern, so it means an upper case or lower case character in the range.

If you were wanting to match a lower case word ‘hello’ then the pattern is (hello).

Sorry, I’m not following you anymore. I can already find the string hello with word boundary using the \bhello\b pattern. What I’m looking to do extra is to be able to match either Hello or hello or HELLO or even hElLo or any other combination of upper/lowercases.

Adding the i flag would do that. Not sure what else does.

Just throwing this out there as I didn’t follow the thread too closely; you can try putting the flag modifier “(?i)” in front of your regex to indicate that it is case insensitive.

You are definitely right that it would be better to have access to the flags setting…maybe something @Bubble can add.

However for the specific test of Hello in any case, you could use the or operator coupled with the word boundary.

Closure: Using Regex alone I was only able to get it to pick up both Hello and hello (where ‘hello’ here is just a proxy for any dynamic text). It did not however pick up HELLO or crazy case usage like heLLo.

But leave it to Bubble to have a much simpler solution sitting there all along … I just prepended my ‘:extract with regex’ tag with a ‘lowercase’ tag, and voila, it picks up everything.

2 Likes

Excellent!

This topic was automatically closed after 70 days. New replies are no longer allowed.