基本正则表达式含义?

use*_*916 1 php regex preg-match

我有这个正则表达式:

'/^ANSWER\:(.+?)$/'
Run Code Online (Sandbox Code Playgroud)

我知道这大致翻译为:

以"ANSWER:"开头的字符串......

我不确定是什么

(.+?)$
Run Code Online (Sandbox Code Playgroud)

翻译成?任何帮助将不胜感激!

And*_*ark 7

(       # begin capturing group
  .+?     # match any character (.) one or more times (+) as few times as possible (?)
)       # end capturing group
$       # end of string anchor (or end of line anchor, if multiline option is enabled)
Run Code Online (Sandbox Code Playgroud)

以下链接有一个很好的正则表达式语法摘要:http:
//www.regular-expressions.info/reference.html

  • `.+`是贪婪的(匹配尽可能多的字符),`.+?`是懒惰的(匹配尽可能少的字符).因此,对于字符串""red blue"`,`.+ e`将匹配整个字符串,但`.+?e`将匹配`"re"`. (4认同)