且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

匹配两个不同令牌之间的任何字符串

更新时间:2023-02-22 12:35:07

/x(.*?)y/g 其中 x 是开始标记和 y 结束标记.

/x(.*?)y/g where x is the beginning token and y the ending token.

这个正则表达式的意思是:匹配任何东西(.),任意次数(*),尽可能少(?).

This RegEx means: match anything (.), any number of times (*), as few times as possible (?).

你的问题的一个直接例子是:

A direct example from your question would be:

/\[begin-match\](.*?)\[end-match\]/g

示例文本现在位于第一个捕获组中.

The sample text is now in the first capturing group.