Struggling again with these. I'm getting confused as to how many of the backslashes should be escaped. I'm trying to convert some like these from Perl, inside quotes:
"^(([ ]{0,3}([*+-])[ t]+)(?s:.+?) (z|n{2,}(?=S)(?![ t]*[*+-][ t]+)))"
Is there a rough rule of thumb for when converting Perl regexen to newLISP -what should be escaped and what shouldn't?
Quote from: "cormullion"
Is there a rough rule of thumb for when converting Perl regexen to newLISP
Yes, don't. Use awk. It may be wordy but at least it is comprehensible.
What would be the benefit of using regexen via Awk rather than in PCRE via newLISP? Looks very much the same sort of thing to me...
With awk you can break it up into program steps. Better yet is to get rid of all those awful special characters in regular expressions. Here is a discussion of a possible LISPy way out of Perl/regex hell:
//http://c2.com/cgi/wiki?AlternativesToRegularExpressions
Hmm - some interesting musings there, but nothing practical or immediately useful. I'd rather struggle a bit with regular expression, imperfect though they may be, than completely fail in an attempt write a context-free grammar parser or whatever is needed.
You may have a look at the regex-coach:
http://weitz.de/regex-coach/
(Written in lispworks common-lisp)
Hi cormullion!
Since I know you're using a Mac and Hans-Peter's recommendation runs on windows only, I'll mention my favorite regex helper: RegExhibt (//http).

(//%3C/s%3E%3CURL%20url=%22http://homepage.mac.com/roger_jolly/software/pics/RegExhibit_Screen.png%22%3E%3CLINK_TEXT%20text=%22http://homepage.mac.com/roger_jolly/sof%20...%20Screen.png%22%3Ehttp://homepage.mac.com/roger_jolly/software/pics/RegExhibit_Screen.png%3C/LINK_TEXT%3E%3C/URL%3E%3Ce%3E)
This is the fourth one I've tried so far, and I think this regex helper is head and shoulders above the others.
Also, if you will be doing a lot of regexing (or cssing, htmling, or even javascripting), I highly recommend The VisiBone Browser Book (//http). I used this heavily during the edit of the newLISP manual and while making the neglOOk website. When I think how useful it's been to me, I'm sorry I didn't mention it earlier!
m i c h a e l
There are two-inch-thick books on the differences between the different regex flavors. PCRE is something of a standard, and that's the library newLISP uses. newLISP has better regex support than most other languages. The only thing it lacks is named groups, which I think were invented for Python and are not standard; but it does have recursion, I believe, using ?R syntax.
I usually put regular expressions between {} so I don't have to double-escape. Your expression should be able to be used verbatim between [text] tags (since it uses curly braces, curly braces would need to be escaped).
thanks - that's the sort of help i'd been hoping for!
Quote from: "cormullion"
Struggling again with these. I'm getting confused as to how many of the backslashes should be escaped. I'm trying to convert some like these from Perl, inside quotes:
"^(([ ]{0,3}([*+-])[ t]+)(?s:.+?) (z|n{2,}(?=S)(?![ t]*[*+-][ t]+)))"
Holy Schneikees! What is *that* supposed to do? :-)
Seriously, whenever I write monstrosities like that, either I put a massive amount of comments explaining what each piece does, or I break up the regex string into smaller strings and assign them to meaningful symbol names (if only for my own benefit when I look at the code more than a week later). But you probably got this from non-cormullion code, right?
Sorry I can't help -- I always have to look it up in a book. I was doing OK until I got to (?s:.+?). :-)
Yes, horrible things. I think it was Markdown lists or headers I was trying to match. It's those positive and negative lookaheads that hurt my brain the most.
I had originally hoped to just copy these regexes without looking 'inside them', but they didn't work first time... And then you start tinkering with them, adding backslashes etc. and it all starts to come unstuck ;-(
Quote from: "Jeff"
Your expression should be able to be used verbatim between [text] tags (since it uses curly braces, curly braces would need to be escaped).
It's possible that curly braces might work - the manual quoth "Balanced nested curly brackets may be used within a string. This aids in writing regular expressions or short sections of HTML."
I might investigate, when I'm feeling more optimistic about regexes...
Thanks Jeff!
Another WIN-only tool for regex:
http://www.regexbuddy.com
Not free but with 29.95 € affordable.
Very easy to make and analyse a regex.
Also it's big brother powergrep is worth a look. (But not cheap)
Quote from: "rickyboy"
Holy Schneikees! What is *that* supposed to do?
Only a nitwit would write something like that or spend time figuring out what it did. I must say that the excessive use of macros in LISP is another example of this syndrome. I don't care how rich he is, Paul Graham is dead wrong.
Clear, concise, and simple is what I strive for. Complexity for its own sake is horse shit.
Quote
Only a nitwit would write something like that or spend time figuring out what it did.
Paste it in RegexBuddy and let explain it:
HTML:
http://hpwsoft.de/anmeldung/html1/newLISP/NewLispRegexPost.htm
Hardcopy:
http://hpwsoft.de/anmeldung/html1/newLISP/NewLispRegexPost.png
Syntax should be as clear as possible. Some algorithms cannot be expressed simply, because they are not simple algorithms.
Quote from: "HPW"
Paste it in RegexBuddy and let explain it:
I would have to get a M$ Windoze system in order to do that. That seems like going from bad to worse! ;-)
That's neat, HP - almost makes it look sensible...!
There are indeed plenty of nitwits who write stuff like that - I just wanted some shortcuts to avoid having to be one of them!
Quote from: "Jeff snipilly"
Syntax should be as clear as possible. Some algorithms cannot be expressed simply, because they are not simple algorithms.
They can however be broken up into simpler pieces, it's called modular programming. Regexes suck because they 1) don't do that and 2) use such terse symbols that one need constantly double escape stuff in order to accomplish the string search.
Hello... we're not using 115 baud teletype machines any longer. The apparent need for robots to decode regex expressions proves that the Perl and regex coders of complex expressions aren't clever, they are nitwits.
Quote from: "jrh"
Only a nitwit would write something like that or spend time figuring out what it did.
Ha, ha, ha, ha! Good one.
Quote from: "jrh"
Clear, concise, and simple is what I strive for. Complexity for its own sake is horse shit.
Am I the only one who noticed that you emphasized *clear*? I quite agree with you here, and in precisely the order you listed the characteristics. Simplicity in expression is usually gotten to automatically after one strives first for clarity and economy.
I love clarity, simplicity, and economy too...
Given a choice between using 'awk' and deciphering regex - um, can I have another choice? :-)
There is a new companion-product of Regexbuddy:
http://www.regexmagic.com/
This is not a regex editor, it seems to be a generator.
I will have a closer look.
heeee cormullion..I completly missed your enhancement on this tool..
need to download that right away... A nice visual addon for my
"Perl 5 Desktop Reference pocket from 1996" ;-) I just recovered
from shelf, hidden behind a Tcl-Pedia-Book the size of a b/w-TV
(a good place to hide btw.. being a pocket containing Perl..)..
.. Only 19.95 euro for a regEx tool..
Great.. now if they only would remove the regex-part from it,
which is clearly simply with that tool,i would be pleased to pay
'Only 19.95 euro' for it..
Meanwhile im doing, and will be for the next week,
some masogistic regex debugging I not happy about..
you mean //http://unbalanced-parentheses.nfshost.com/downloads/grepper.lsp.txt.src.html ? I suppose that still works?!