Variable length look-behind

后端 未结 5 1146
猫巷女王i
猫巷女王i 2020-12-16 13:38

Is there any elegant solution to build a variable length look-behind regex such as this one ?

/(?<=eat_(apple|pear|orange)_)today|yesterday/g;

5条回答
  •  -上瘾入骨i
    2020-12-16 14:03

    Alternative solution - reverse the string and use lookahead instead. It may look ugly having to write the pattern words in reverse but it's an option when everything else fails.

提交回复
热议问题