gpt4 book ai didi

php - 单词的正则表达式

转载 作者:可可西里 更新时间:2023-10-31 22:06:44 25 4
gpt4 key购买 nike

我正在用 PHP 解决字符串解析问题。我想要字典中单词的正则表达式。该词只能包含 A-Z 和 a-z。我想出了这个正则表达式,但这似乎不起作用。有人可以帮忙吗。

$regexp = "/[A-z]+/";
if(preg_match($regexp,$buffer)){
print $buffer . "<BR>";
}

添加 rkt 的评论以提高可读性

目前正在使用这个正则表达式

$regexp = "/[A-Za-z]+/";

但仍然有很多不相关的词被打印出来,例如。

a.new,#quickbar a.new{color:#ba0000} enwiki:resourceloader:filter:minify-css:5:f2a9127573a22335c2a9102b208c73e7 wgNamespaceNumber=0;
wgAction="view";
wgPageName="Roger_Federer";
wgMainPageTitle="‌​Main Page";
wgWikimediaMobileUrl="http:\/\/en.m.wikipedia.org\/wiki";
document.writeln("\x3cdiv id=\"localNotice\"\x3e\x3cp\x3e\x3c/p\x3e\n\x3c/div\x3e");

最佳答案

如果只想匹配整个单词...

/\b[A-Z]+\b/i

关于php - 单词的正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6300642/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com