javascript - merge / join regular expression results for highlighting -
i want join/merge result of regular expression.
for example, string
hello foo bar
the regex result pattern /el/
=> el
regex result pattern /llo\sfo
=> llo fo
if use pipe, result 1 match.
pattern /el|llo\sfo/
result el
my desired result should ello fo
use case highlighting multiple pattern in text.
the regex engine processes string once. after character has been consumed, cannot processed again (lookarounds don't count matter because "just look").
since patterns need "overlap" on example string, never match (in 1 regex). however, global flag g
, following input:
"helllo foo bar".match(/el|llo\sfo/g)
so solution use 2 separate regexes purpose.