regex - How do I check if a string has exactly one of a certain character -
i'm trying scan strings see if have 1 of character.
for example if i'm looking question mark
hello? i'm here will match regex however
hello? listening? will not
i've tried ?{1} , ?{1}[^?]+ both don't work. can point me in right direction?
why not do:
(\?) and count number of matches.
or more simply, count number of ? in string using tr///
my $c = $string1 =~ tr/?//;
Comments
Post a Comment