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

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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

 



Rivotti
User

Apr 6, 2000, 3:25 PM

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

Hi:

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
Rivotti


Jasmine
Administrator / Moderator

Apr 6, 2000, 4:21 PM

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

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.



Rivotti
User

Apr 7, 2000, 1:42 AM

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

Thanks Jasmine.
Rivotti

 
 


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

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