I want to join/merge the result of a regular expression.
For example, this is the string
hello foo bar
the regex result for the pattern /el/
=> el
the regex result for the pattern /llo\sfo
=> llo fo
If I use pipe, the result is only one match.
for this pattern /el|llo\sfo/
the result is only el
My desired result should be ello fo
The use case is for highlighting multiple pattern in a text.
The Regex engine only processes the string once. After a character has been consumed, it cannot be processed again (Lookarounds don't count for that matter because they "just look").
Since your patterns would need to "overlap" on your example string, they will never match together (in one regex). They would however, with the global flag g
and the following input:
"helllo foo bar".match(/el|llo\sfo/g)
So the only solution is that you use two separate regexes for your purpose.