
Jasmine
Administrator
/ Moderator
Apr 6, 2000, 4:21 PM
Post #2 of 3
(1513 views)
|
Perl documentation on Regular Expressions: http://www.perlguru.com/perldocs/pod/perlre.html To find out if a word ends in a particular character and then delete that character, you would use a simple substitution expression. Pattern matches with substitions are made in this format: $texttocheck =~ s/findthis/replacewiththis/; To look for something at the end of the string, you need to enter a dollar sign after the text to match. $texttocheck =~ s/findthis$/replacewiththis/; To look for something at the beginning of the string, put a caret in front of the text to match. $texttocheck =~ s/^findthis/replacewiththis/; So if you want to remove the last s from a string, your code would look like this: <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR> $word = "Take this"; $word =~ s/s$//; print $word; # prints Take thi </pre><HR></BLOCKQUOTE> The following code will catch most incorrectly formatted email addresses: <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR> if ($email =~ /^[\w\-]+[\w\-\.]*\@[\w\-]+[\w\-\.]*\.[A-Za-z][A-Za-z]+$/){ #email is valid } else{ #email is not valid } </pre><HR></BLOCKQUOTE> There's no way other than actually sending an message to an email address (and perhaps getting a bounced message) to determine if it actually exists.
|