Mar 9
We gave some examples of regular expressions.
Perl:
$foo = q(This is some text. Jim's email is jim@there.com. z@z But there are other @ and @. things. Can you extract the first.last@place.foo.com things?);
print $foo . "\n";
if (@answer = $foo =~ /[a-z0-9.]+@[a-z0-9.]+\.[a-z]+/gi) {
print "yes : @answer \n";
}
else {
print "no\n";
}
Python:
import re
foo = """This is some text. Jim's email is jim@there.com. z@z But there are other @ and @. things. Can you extract the first.last@place.foo.com things?"""
print foo
answer = re.findall(r"[a-z0-9.]+@[a-z0-9.]+\.[a-z]+", foo, flags=re.IGNORECASE)
if (answer):
print "yes: " + str(answer)
else:
print "no"
printing primes with regex (by Abigail):
perl -e'while($.++<99){$_.=1;print$..$/if!/^1?$|^(11+?)\1+$/}'