Hi
I am trying to write a regular expression in perl that will match the first letter / character of a string and the last letter / character of the string. I have this statement for my expression.
Code:
if ($string =~ m/(^([a-z]+\s*)+$)/)
I think this is not correct, because I know that the ^ is used to match the first part of the string while the $ sign is used to match the ending part of string. i am not sure about my code, still I am posting my code, please help me.
Code:
#!/usr/bin/perl
while ()
{
print "enter something: \n";
chomp ($string =<STDIN>);
if ($string =~ m/(^([a-z]+\s*)+$)/)
{
print "Found letter '$1' was found ", pos($text), " \n";
print "This string begins and ends with same character with \n";
last;
}
else
{
print "This string does not begin and end with the same character \n";
}
}
Bookmarks