Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我试图搜索一个以任何字符(大写字母)开头但在 perl 中以零结尾的单词。例如
ABC0 XYZ0 EIU0 QW0
我试过的 -
$abc =~ /^[A-Z].+0$/
但我没有得到正确的输出。有人可以帮我吗?
^字符串开头的锚点,结尾处的锚点$。.+匹配尽可能多的非换行符。所以
^
$
.+
"ABC0 XYZ0 EIU0 QW0" =~ /^[A-Z].+0$/
匹配整个字符串。
\b断言在单词边缘匹配:单词字符和非单词字符在任何地方都是相邻的。charclass\w只包含单词字符,\Scharclass 包含所有非空格字符。其中任何一个都比..
\b
\w
\S
.
所以你可能想使用/\b[A-Z]\W*0\b/.
/\b[A-Z]\W*0\b/
这可能有效:
$abc =~ /\b[A-Z].*0\b/
\b 匹配单词边界。