CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
Regular expression...



Apr 6, 2000, 3:25 PM

Post #1 of 3 (1733 views)
Regular expression... Can't Post


I have some problems understanding regular expressions. Is there any documentation on-line I could read?

Meanwhile, how do I check if a string ends in a "s" and, if true, how to delete the same character?
Ex: Catching Words # ends in a "s"
Catching Word # string changed

Another thing, what's the best way to validade a given E-mail in a form? And how do check if the E-mail addres exists?

Thanks in advance

Administrator / Moderator

Apr 6, 2000, 4:21 PM

Post #2 of 3 (1733 views)
Re: Regular expression... [In reply to] Can't Post

Perl documentation on Regular Expressions:

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

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
#email is not valid

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.


Apr 7, 2000, 1:42 AM

Post #3 of 3 (1733 views)
Re: Regular expression... [In reply to] Can't Post

Thanks Jasmine.


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives