我有一个很长的模板,我需要根据某些模式从中提取某些字符串。当我浏览一些示例时,我发现在这种情况下使用量词很好。例如以下是我的模板,我需要从中提取while
和doWhile
.
This is a sample document.
$while($variable)This text can be repeated many times until do while is called.$endWhile.
Some sample text follows this.
$while($variable2)This text can be repeated many times until do while is called.$endWhile.
Some sample text.
我需要提取整个文本,从$while($variable)
until开始$endWhile
。然后我需要处理 $variable 的值。之后,我需要在原始文本之间插入文本$while
。$endWhile
我有提取变量的逻辑。但我不确定如何在这里使用量词或模式匹配。有人可以为此提供一个示例代码吗?任何帮助将不胜感激