Liste des Groupes | Revenir à cu shell |
On 20.11.2024 12:46, Ed Morton wrote:I have no problem working with regexps, I just don't write lengthy or complicated regexps, just brief, simple BREs or EREs, and I don't restrict myself to trying to solve problems with a single regexp.>(Worth a scribbling on a WC wall.)
Definitely. The most relevant statement about regexps is this:
>Some people, when confronted with a problem, think "I know, I'll use
regular expressions." Now they have two problems.
>Regexps are nothing for newbies.
Obviously regexps are very useful and commonplace but if you find you
have to use some online site or other tools to help you write/understand
one or just generally need more than a couple of minutes to
write/understand it then it's time to back off and figure out a better
way to write your code for the sake of whoever has to read it 6 months
later (and usually for robustness too as it's hard to be sure all rainy
day cases are handled correctly in a lengthy and/or complicated regexp).
The inherent fine thing with Regexps is that you can incrementally
compose them[*].[**]
It seems you haven't found a sensible way to work with them?
(And I'm really astonished about that since I know you worked with
Regexps for years if not decades.)
In those cases where Regexps *are* the tool for a specific task -Right, I don't, but I see many people using them for tasks that could be done more clearly and robustly if not done with a single regexp.
I don't expect you to use them where they are inappropriate?! -
what would be the better solution[***] then?It all depends on the problem. For example, if you need to match an input string that must contain each of a, b, and c in any order then you could do that in awk with this regexp or similar:
Janis
[*] Like the corresponding FSMs.
[**] And you can also decompose them if they are merged in a huge
expression, too large for you to grasp it. (BTW, I'm doing such
decompositions also with other expressions in program code that
are too bulky.)
[***] Can you answer the question that another poster failed to do?
Les messages affichés proviennent d'usenet.