MatchText, MatchChunk and the needle in the haystack
Peter Alcibiades
palcibiades-first at yahoo.co.uk
Wed Mar 21 04:32:42 EDT 2007
Can you do it with a text editor and regular expressions? I'm genuinely
diffident about asking, because you all have so much more experience that if
it were this easy, you'd have suggested it. But anyway, is there something
wrong with the following?
I made up a fragment of a file like this in the form
02-Mar-92sometext01-Sep-04somemore text........and a few more entries of the
same sort.
Then opened it in Kate (but presumably all programming editors have similar
functionality?)
Then did a match with regular expressions in the Find part of the menu. It
helped construct the following expression:
[\d][\d]-[\D][\D][\D]-[\d][\d]
which really would not have been so very hard to figure out unaided - a
classic case of the obligatory gui getting in the way of your typing. This
picks up all dates and it obviously misses other hyphenated expressions.
Then in the replace section I put
Enter\0
It uses the \0 as backwards reference, so to include all the found string in
the replacement.
The only hard part, all of ten seconds, was that I didn't seem able to enter a
line feed character directly, like by \n for instance, but I just copied and
pasted one and bingo, it worked fine. I ended up with a bunch of lines like
this:
02-Mar-92sometext
01-Sep-04somemore text.. and so on.
Was that what was wanted?
This was almost instant. I guess if I'd a lot to do, I would think of an awk
one liner, but have forgotten how to do backward references in awk. And it
would be even more embarrassing to have both got the above all wrong and to
also cite duff awk scripts!
Peter
More information about the use-livecode
mailing list