In regex, match either the end of the string or a specific character

前端 未结 2 1168
渐次进展
渐次进展 2020-11-22 07:19

I have a string. The end is different, such as index.php?test=1&list=UL or index.php?list=UL&more=1. The one thing I\'m looking for is

2条回答
  •  情书的邮戳
    2020-11-22 07:45

    Use:

    /(&|\?)list=.*?(&|$)/
    

    Note that when you use a bracket expression, every character within it (with some exceptions) is going to be interpreted literally. In other words, [&|$] matches the characters &, |, and $.

提交回复
热议问题