Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Useful regular expression tutorial [closed]

Tags:

regex

grep

Is there a good tutorial on using regular expressions, especially with grep? I tried googling for some, but most tutorials are too basic and cover things I already know.

like image 726
hhafez Avatar asked Dec 02 '08 01:12

hhafez


People also ask

Which are 3 uses of regular expression?

Regular expressions are used in search engines, in search and replace dialogs of word processors and text editors, in text processing utilities such as sed and AWK, and in lexical analysis.

What does \\ s+ mean in regex?

The plus sign + is a greedy quantifier, which means one or more times. For example, expression X+ matches one or more X characters. Therefore, the regular expression \s matches a single whitespace character, while \s+ will match one or more whitespace characters.

What is difference [] and () in regex?

[] denotes a character class. () denotes a capturing group. [a-z0-9] -- One character that is in the range of a-z OR 0-9. (a-z0-9) -- Explicit capture of a-z0-9 .

What is the use of \\ in regex?

You also need to use regex \\ to match "\" (back-slash). Regex recognizes common escape sequences such as \n for newline, \t for tab, \r for carriage-return, \nnn for a up to 3-digit octal number, \xhh for a two-digit hex code, \uhhhh for a 4-digit Unicode, \uhhhhhhhh for a 8-digit Unicode.


2 Answers

Regular-expressions.info has a tutorial section. This site is pretty comprehensive for regular expressions in general, although the emphasis is on support in scripting and programming languages.

The J. Friedl book on mastering regular expressions (mentioned elsewhere), is definitely an outstanding resource, and essential reading if you are serious about doing what the title says.

Anyone who uses regular expressions routinely, or as part of their job, would do well to pick up the book. Browsing around for tutorials is not really conducive to proficiency, in regex-land.

like image 63
dreftymac Avatar answered Oct 16 '22 20:10

dreftymac


Here is an introductory article. Here are some other tutorials.

The definitive book is Mastering Regular Expressions by J. Friedl:

alt text http://ecx.images-amazon.com/images/I/51fSgodb1uL._BO2,204,203,200_PIsitb-sticker-arrow-click,TopRight,35,-76_AA240_SH20_OU01_.jpg

like image 43
Federico A. Ramponi Avatar answered Oct 16 '22 20:10

Federico A. Ramponi