这个正则表达式模式意味着什么:'/&\ w; /'

1 php regex

有人可以解释一下这个功能

preg_replace('/&\w;/', '', $buf)
Run Code Online (Sandbox Code Playgroud)

呢?我查看了各种教程,发现它/&\w;/用字符串替换了模式''.但我无法理解这种模式/&\w;/.它代表什么?

同样地

preg_match_all("/(\b[\w+]+\b)/", $buf, $words)
Run Code Online (Sandbox Code Playgroud)

我无法理解字符串"/(\b[\w+]+\b)/"代表什么.

请帮忙.提前致谢 :)

Sub*_*niC 11

你的第一个表达式的解释很简单,它是:

&     # Match the character “&” literally
\w    # Match a single character that is a “word character” (letters, digits, and underscores)
;     # Match the character “;” literally
Run Code Online (Sandbox Code Playgroud)

第二个是:

(           # Match the regular expression below and capture its match into backreference number 1
   \b          # Assert position at a word boundary
   [\w+]       # Match a single character present in the list below
                  # A word character (letters, digits, and underscores)
                  # The character “+”
      +           # Between one and unlimited times, as many times as possible, giving back as needed (greedy)
   \b          # Assert position at a word boundary
)
Run Code Online (Sandbox Code Playgroud)

preg_replace函数使用正则表达式.正则表达式允许您以非常强大的方式在文本中查找模式.

为了能够使用这样的函数preg_replace,preg_match我建议你先看一下正则表达式的工作原理.

你可以在这个网站上收集很多信息http://www.regular-expressions.info/

您可以使用软件工具来帮助您理解正则表达式(如RegexBuddy)