A
A
Anthony Barkovsky2020-01-30 19:51:16
Python
Anthony Barkovsky, 2020-01-30 19:51:16

How to build a regex correctly?

Good day. It is necessary to get everything

from the string up to HI.JKL , that is: . Despite the fact that the numbers and letters can be different, the numbers can be either 1, 2, or 120, 130, etc. So far, I have only come to , which displays only up to the first digit with a dot. At the same time, in python re.findall(r,s) this expression for some reason does not display anything, although it works on any online regex builder. It would be possible to repeat this expression three times, but it will look stupid and I'm not sure what is right. I will be glad to any advice. A.B.CD.1.EF.2.G.3.HI.JKLA.B.CD.1.EF.2.G.3.

^(.*?)*[0-9]\.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
DevMan, 2020-01-30
@velvetflower

(.*)\w{2}\.
https://regex101.com/r/4NB8EQ/1

D
Dr. Bacon, 2020-01-30
@bacon

why is regex here?
'A.B.CD.1.EF.2.G.3.HI.JKL'.split('HI.JKL')[0]

V
Vyacheslav, 2020-01-30
@ElefanObi

Judging by the description of the task, the following expression will suit you:
(([AZ]|\d)+\.?)+(?=\.\w+\.\w+)
https://regex101.com/r/zpNzD4/2

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question