运行 ❯
获取您的
自己的 PHP
服务器
×
更改方向
更改主题,深色/浅色
转到 Spaces
<!DOCTYPE html> <html> <body> <h1>Regex Modifier: [123]</h1> <p>How many characters in the text "W3Schools has been live since 1999" is either the number "1", "2", or "3":</p> <?php $txt = "W3Schools has been live since 1999"; $pattern = "/[123]/"; echo preg_match_all($pattern, $txt); ?> <p>The matches were found here:</p> <?php echo preg_replace($pattern, "#", $txt); ?> <p>(Each match was replaced by a # character)</p> </body> </html>
正则表达式修饰符: [123]
文本“W3Schools has been live since 1999”中,数字“1”、“2”或“3”出现了多少次?
2
匹配结果如下
W#Schools has been live since #999
(每个匹配项都替换成了“#”字符)