I have got below string and I need to Get all the values Between Pizzahut: and |.
ABC:2fg45rdvsg|Pizzahut:j34532jdhgj|Dominos:3424232|Pizzahut:3242237|Wendys:3462783|Pizzahut:67688873rg|
I have got RegExpression .scan(/(?<=Pizzahut:)([.*\s\S]+)(?=\|)/)
but it fetches
"j34532jdhgj|Dominos:3424232|Pizzahut:3242237|Wendys:3462783|Pizzahut:67688873rg|"
Result should be: 34532jdhgj,3242237,67688873rg
You can use
See this Ruby demo and the Rubular demo.
It does not look possible that you have
Pizzahut
as a part of another word, but it is possible, use a version with a word boundary,/\bPizzahut:([^|]+)/
.The
Pizzahut:([^|]+)
matchesPizzahut:
and then captures into Group 1 any one or more chars other than a pipe (with([^|]+)
).Note that
String#scan
returns the captures only if a pattern contains a capturing group, so you do not need to use lookarounds.