Regular Expressions

Hi

I would like to get some explanations about regular expressions. For example if we have expression like this /[Blb]it$/ what would be match for this regular expression i mean words that would match this expression and if an expert can give me little explanation.

Also if for example I want to find out the expression that would match ask@me.com what expression I would need to use


Also I would like to get explanation for example if I am copying something
for example if i go to   cd /home/test  directory and I copy content of a folder like cp -rfp /home/new/* . what the asterisk and dot mean at the end of syntax

Thanks
cer113Asked:
Who is Participating?
 
farzanjCommented:
/[Blb]it$/  Matches

Bit  --at the end of line
lit   --at the end of line
bit  --at the end of line

$ matches at the end
[Blb] matches any one character out of B or l or b
 
Regular expression for ask@me.com
What language?
In sed it should be /ask\@me\.com/
Same in Perl

cp -rfp /home/new/*
This is NOT a regular expression.  It is globbing. * matches anything and . means dot--literally, unlike regular expressions where . means one character.
0
 
farzanjCommented:
In the last example * is the wild card and it could match almost any character.  Wild cards are not nearly as powerful as regular expressions.
http://tldp.org/LDP/abs/html/globbingref.html
0
 
cer113Author Commented:
thanks for your information

what forward slash / means in regular expression

I will accept farzan solution since it explains very nice how it works
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
wesly_chenCommented:
It mean "match".

$STRING ~ /<reg exp>/
if $STRING match <reg exp>, then ...
or
echo $STRING | sed '/<reg exp>/'
0
 
cer113Author Commented:
Regular expression for ask@me.com
What language?
In sed it should be /ask\@me\.com/
Same in Perl


Will this give me all e mail addresses that end up with domain me.com
0
 
pmasottaCommented:
Regular expressions is a very powerfull tool full of easy-to-forget rules...
but knowing the topic is always a good investment.
When I was learning them I started like you, solving specific needs; yes I was getting things done but I wasn't really learning the topic.
Then I decided to take a more systematic approach beyond any specific need and that helped me a lot.

The book that gave me the structured approach was
http://www.amazon.com/sed-awk-2nd-Dale-Dougherty/dp/1565922255/

The quick reference
http://www.amazon.com/sed-awk-Pocket-Reference-2nd/dp/0596003528/

for practicing and see what every regex match get from this site the Notepad with regex extension. its very handy
http://www.codeproject.com/KB/recipes/notepadre.aspx

0
 
cer113Author Commented:
ya i know i have to learn but just for the beginning i would take some commands and based on explanation i would learn.

So for example if i want to retrieve all mails that end up with me.com how would i write regular expression
would I use find or how it goes
0
 
pmasottaCommented:
A regular expression is just a set of rules for matching a piece of text, after that every app does an specific job on the matched  text.

let say:
sed (string editor) is able to replace/modify/erase those matchings...
awk somethig similar
grep is able to find and list files that contain certain patterns expressed by regex
the application I'm coding now use regex for validating user input correctness on dialog boxes edit controls.
etc

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.