lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Paul Smith a écrit :
I think the main problem people have is that they are difficult to read 'at a glance'. Once you realise that they are often quite comprehensible once you start breaking them down, they become a lot easier, but a lot of people will look at them, and because they don't understand it immediately, the little switch that says 'I can't do this' trips, and they will say that regexps are hard and they can't do them without actually trying.

Exactly! Using the x mode (with line breaks, comments and indentation) can be useful too with complex expressions like:
^((0[1-9]|1\d|2[0-8])/(0\d|1[012])/(1[6-9]|[2-9]\d)\d{2}|(29|30)/(0[13-9]|1[012])/(1[6-9]|[2-9]\d)\d{2}|31/(0[13578]|1[02])/(1[6-9]|[2-9]\d)\d{2}|29/02/((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|(16|[2468][048]|[3579][26])00))$

If people were introduced to regexps by things like

gr[ea]y

rather than

\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b

they'd probably find them a lot easier... I think the difficulty is mainly a mind-set one rather than actual difficulty.

Exactly. Tired of seeing tutorial matching aaaacbbb, useful only for people parsing DNA sequences :-), I made my own tutorial trying to use real-world example and only previously seen concepts (no forward references).
For the curious-minded and critical eyes, it is at:
http://Phi.Lho.free.fr/programming/RETutorial.en.html
Private mails for remarks, it is off topic...

--
Philippe Lhoste
--  (near) Paris -- France
--  http://Phi.Lho.free.fr
--  --  --  --  --  --  --  --  --  --  --  --  --  --