After wasting 30 minutes trying to refine a request on two AI engines (including ChatGPT), I’m less worried about AI taking over the world. Wondering if a human could help me come up with a regular expression that will work for my needs.
I have your basic Type-to-Select component. I just want to split a string into parts so that I can bold what the user has entered. I need a regular expression to use with String.split/3
.Here’s the result I’m looking for.
- There is a
search_string
and aninput_string
. - If the
search_string
is found at the beginning or end of theinput_string
, then I’d get 2 parts from String.split/3 - If the
search_string
is found in the middle of the input_string, then I’d get a maximum of 3 parts fromString.split/3
. - It needs to be case-insensitive
For example:
search_string: "san"
input_string: "San Francisco, California, US"
I would get two parts: ["San", " Francisco, California, US"]
NOTE: Spaces need to be preserved for when I join it back together
search_string: "fran"
produces 3 parts: ["San ", "Fran", "cisco, California, US"]
search_string: "US"
produces 2 parts: ["San Francisco, California, ", "US"]