G
G
grachev_goga2022-02-08 21:36:59
Regular Expressions
grachev_goga, 2022-02-08 21:36:59

I can't compose a regular expression, what am I doing wrong?

Good afternoon.
Need help, already broke my head.
There is a list:
fb.ru
avto.ru
solitaire.classicgame.klondike.solitaire.freecard
solitaire.patience.card.games.klondike.free
blabla.ru
tadasuda.ru
From this list, you need to select the following lines according to the model of
solitaire.classicgame.klondike .solitaire.freecard
solitaire.patience.card.games.klondike.free
They can be shorter or longer but generally there are always 3-4 dots in the text.
Tried:
[a-zA-Z0-9]+\.[a-zA-Z0-9]+\.[a-zA-Z0-9]+\.[a-zA-Z0-9]+
\w+ .\w+.\w+.\w+
and many other options, please help with composing a regular expression.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
grachev_goga, 2022-02-09
@grachev_goga

Thanks to all.
The option (\w+\.){3,}\w+ came up the most,
so I thought of the option, go from the opposite, minus at the end in the .ru .com domain zone, etc.

P
PavelMos, 2022-02-09
@PavelMos

if you need to take 3 or 4 points, then first make an expression for 2 points, and then use the OR construction, which is also an alternation that will take the next 1 or 2 points.
[a-zA-Z0-9]+\.[a-zA-Z0-9]+ (\.[a-zA-Z0-9]+\.[a-zA-Z0-9]+\.[ a-zA-Z0-9]+)
https://regex101.com/r/10ZqvF/1
Here, for example, about this:
https://learn.javascript.ru/regexp-alternation

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question