[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Regular Expressions

Posted on 2011-05-11
Medium Priority
Last Modified: 2012-05-11

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

Question by:cer113
  • 3
  • 2
  • 2
  • +1
LVL 31

Accepted Solution

farzanj earned 2000 total points
ID: 35743724
/[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.
LVL 31

Expert Comment

ID: 35743730
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.

Author Comment

ID: 35743829
thanks for your information

what forward slash / means in regular expression

I will accept farzan solution since it explains very nice how it works
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

LVL 38

Expert Comment

ID: 35743910
It mean "match".

$STRING ~ /<reg exp>/
if $STRING match <reg exp>, then ...
echo $STRING | sed '/<reg exp>/'

Author Comment

ID: 35743920
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
LVL 11

Expert Comment

ID: 35744052
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

The quick reference

for practicing and see what every regex match get from this site the Notepad with regex extension. its very handy


Author Comment

ID: 35745112
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
LVL 11

Expert Comment

ID: 35745361
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.


Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses
Course of the Month19 days, 11 hours left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question