A
A
Alexey Nikolaev2014-10-22 21:37:50
Programming
Alexey Nikolaev, 2014-10-22 21:37:50

How to understand regular expressions?

Good time.
Are there normal, detailed tutorials on regular expressions, with examples and their detailed analysis? All that I found (including the official source, notorious for its scarcity) offer only interpretations of control structures. When I try to understand the meaning of some regular expression or write my own, it does not work (with some exceptions), although logically it should.
I would be grateful for links to manuals, thanks.
PS I also read various articles, but unfortunately, their authors did not find it difficult to write at least a couple of examples and analyze them

Answer the question

In order to leave comments, you need to log in

8 answer(s)
E
Evgeny Petrov, 2014-10-22
@Heian

Books would be better to read.
Jeffrey Friedl Regular expressions
Jan Goyverts, S. Levitan Regular expressions. Recipe collection

U
ugodrus, 2014-10-23
@ugodrus

Evgeny Petrov, I would even stop at Jeffrey Friedl Regular expressions. Books using the word "recipes" are useless in my opinion. Very little content most of the time.
For a general understanding, the first is enough. As for the application, each environment has its own peculiarities of using regular expressions. So the question of practice is the main one. If the author wants to master regulars, for example, under PHP, then there is a wonderful tester . I myself tested and collected a bunch of regulars on it.

D
Denis Ineshin, 2014-10-22
@IonDen

Like this: habrahabr.ru/post/189852

C
Cyril, 2014-10-22
@endemic

You can start from Wikipedia and try to make examples online)
en.wikipedia.org/wiki/Regular_expression
www.regexr.com
As for understanding the meaning of a regular expression: this already comes with some experience. And if the meaning of a regular expression like /d{1,4} is easy to understand, then only a terminator can understand the meaning of a standard regular expression for checking a mail address :)

B
Bambre, 2014-10-30
@Bambre

Plus Friddle. Even for those who are already familiar with regular seasons, this book can very well rebuild their brains.

G
Grigory Vasilkov, 2016-01-29
@gzhegow

You don't have to understand them, you just read them.
Very simple.
^ - start of line
$ - end of line
| - character "or" - used between characters or groups to show "either this or that"
reads as a string consisting of any number of letters from a to z (English small letters) or any number of Russian letters, not including ё , the output will be three samples - the first - the entire string, the second string of English letters, the third - a string of Russian.
But specifically, this code can still be rewritten like this:
Since it makes no sense to separate Russian and English into separate groups. It's just shorter and easier.
. is a "dot". any character, not including quite some types of tabs, line breaks different there
\w - this is a word - that's just any construction from any number of letters
(there are other different ones)
.* - an asterisk means either there or not, in any quantity
.+ - plus - there must be at least one "dot"
.{2,} - from two to infinity "dots"
.{2,5} - from two to five "dots"
/([az][az])/gi - g(global), i(ignorcase) - global means to search in the entire text without taking into account line breaks, if not set, it will search only within one line, ignorcase - will allow do not specify capital letters
/([az][az])/gu - g(global), u(utf-8) - utf8 will allow you to work correctly with Russian letters in utf-8 encoding, a common problem on forums

D
dan-ver, 2014-10-22
@dan-ver

what programming language?

T
Timur, 2014-10-23
@atrian

For complete beginners, I recommend recording the webinar
prog-school.ru/2014/09/zapis-vebinara-regularnye-...
They explain the basics well, after watching the regular seasons ceased to be black magic for me and it became clear where to dig further :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question