Reputation: 21
am trying to search a word where it starts with any character (Capital letter) but ends with zero in perl. For example
ABC0
XYZ0
EIU0
QW0
What I have tried -
$abc =~ /^[A-Z].+0$/
But I am not getting proper output for this. Can anybody help me please?
Upvotes: 0
Views: 59
Reputation: 57640
The ^
anchores at the start of a string, the $
at the end. .+
matches as many non-newline-characters as possible. Therefore
"ABC0 XYZ0 EIU0 QW0" =~ /^[A-Z].+0$/
matches the whole string.
The \b
assertion matches at word edges: everywhere a word character and a non-word-character are adjacent. The \w
charclass holds only word characters, the \S
charclass all non-space-characters. Either of these is better than .
.
So you may want to use /\b[A-Z]\W*0\b/
.
Upvotes: 1
Reputation: 2253
This might work :
$abc =~ /\b[A-Z].*0\b/
\b matches word boundaries.
Upvotes: 0