Using Regex to extract a string between two strings

I am trying to use the extract with Regex function to extract a string that is always sitting between two strings of texts that never change.

Here are 3 examples

  • I want {“key”:“1671291382053x721052777787162600”} to return 1671291382053x721052777787162600
  • I want {“key”:“1671128263833x743710543152935700”} to return 1671128263833x743710543152935700
  • I want {“key”:“1671128291585x470773579005820900”} to return 1671128291585x470773579005820900

When using this regex pattern {“key”:"(.*)"} with this regex builder (which is recommended in Bubble’s manual), it does return what I need. However, when entering this regex pattern and using the extract with regex function in bubble, the full string is returned, i.e. {“key”:“1671291382053x721052777787162600”}, and not just the part that I need, see below:



Anybody has an idea how to solve this?

PS: Note that the string that I am looking to extract is a unique ID of a Bubble thing so there will never be special characters or spaces

https://manual.bubble.io/core-resources/data/operations-and-comparisons#extract-with-regex

Bubble does not expose captured groups and your regex is matching the whole line including what you have before and after the group.
You may want to play with negative lookbehind and lookahead as menrioned in the documentation at the previous link.

Be careful about the browser support for that.

Hi there, @42.decaen… this might be hacky, but you should be able to string together Bubble operators to get what you need, and it might look something like this.

extract

It could be a bit easier than what I am showing there, but today I learned you can’t split by a quotation mark. Who knew, eh? (Probably everyone other than me.)

Hope this helps.

Best…
Mike

:slight_smile:
It could be as easy as this … assuming I understand the question
Screenshot 2022-12-19 at 14.35.01
https://bubble.io/page?type=page&name=regex_extract&id=knowcode-tech&tab=tabs-1
https://knowcode-tech.bubbleapps.io/version-test/regex_extract?debug_mode=true

\d{5,} means any digits at least 5 long

2 Likes

even shorter with \d+x\d+

Hey @mikeloc thank you! Yep this works fine but slightly hacky like you said since Bubble might change at some point the number of characters that a unique ID gets, who knows?

PS: I didn’t know that split by quotation mark was not working, good to know!

1 Like

Hey @lindsay_knowcode Yes this works great! And I checked in Bubble’s manual which confirms that the format of a unique ID follows this pattern: “The unique ID has the format of a long string of seemingly random numbers with an “x” in the middle.”
Thank you!

beautiful! that works!

1 Like

thanks to @lindsay_knowcode that pointed to the right direction :slight_smile:

1 Like

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