RE: [q-lang-users] silly regex wonderings
Brought to you by:
agraef
From: David v. <da...@pu...> - 2004-11-22 05:05:57
|
OK, you've got me playing with these regexes now. Based on the regsplit example, a regex search and replace is: snr Opts OldRE NewRE S = strcat (regex Opts OldRE S (regskip ++ `NewRE) ++ [regskip]); i.e. instead of splitting at a match we're inserting a new regex. Then embolden2 = snr "g" "\\*([^\\*]*)\\*" '(tag "bold" (reg 1)); Note the quote and unquote to delay evaluation of (reg 1) etc. ==> embolden2 "this is some *bold* text, and a lone * at the end" "this is some <bold>bold</bold> text, and a lone * at the end" Slightly more usable: tagify Delim Tag = snr "g" (Delim++"([^"++Delim++"]*)"++Delim) '(tag Tag (reg 1)); embolden3 = tagify "\\*" "bold"; underline = tagify "_" "underline"; Then we can write: ==> underline (embolden3 "This has *bold _underlining_*!") "This has <bold>bold <underline>underlining</underline></bold>!" The problem is ==> underline (embolden3 "This has *bold _underlining*_ !") "This has <bold>bold <underline>underlining</bold></underline> !" And this is malformed html. I'm torn between two instincts here: - A clean way to do it would be to process your wikitext, build a full parse tree and transform this to html, but - this doesn't seem in the wiki spirit, where I suspect the ideal would be to capture the entire conversion to html in a single regex. Cheers, David. |