I have a string like this:
124:111,120:444,103:504,494:120,404:111,200:100,
I will use replace() and let’s say I want to select
124:111,120:444,103:504,494:120,404:111,**200:100,**
without actually defining 200:100,
but instead having it to work like this:
Define only :100, regex selects everything to the left until "," approaches and everything to the right including first "," => 200:100,
Is it possible to have such a regex? Thanks for any information
2
Answers
Without using
replace()
you could do it this way in my opinion.Define the regex pattern and matches any sequence of characters that does not include a comma
Use
match()
to find a match of the pattern in the input string:Check if a match is found
Regex
Will match
:100
and capture the digits before that:split()
Another option is to split on
,
, then check if the right side has the value you’re searching for