如何在php regex的框架括号中找到文本?

时间:2015-07-24 17:31:34

标签: php regex

我有这个php:

(pattern)    Capture group, remembers match for pattern, lets you treat it as one item
(?:pattern)  Non-capture group, forgets match for pattern, lets you treat it as one item
x?           Matching (item) x is optional, greedy
x??          Matching (item) x is optional, non-greedy (not used here)
x+           Match at least one repeat of (item) x, greedy
x+?          Match at least one repeat of (item) x, non-greedy (not used here)
\d           Digit, same as [0-9]
\s           Whitespace, i.e. spaces, tabs, new lines, etc
\.           A literal ".", rather than wildcard (which is what . usually means)
/pattern/ig  pattern is a RegExp literal, i and g are flags
\/           A literal "/", rather than terminating the RegExp literal

我的html中有一些文字,如[[[SOMETHING]]]。我用它们作为标记。但是现在我想把它们全部拿掉并换成一个数字......(一段时间)我的正则表达式不能完成这项工作。这个正则表达式有什么问题?

1 个答案:

答案 0 :(得分:0)

这是您正在寻找的更多内容:\[\[\[(.*?)\]\]\]。这将在您的示例中找到3个括号之间的任何内容。如果要更改要搜索的字符,只需将括号更改为其他字符。