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.


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -