[q-lang-users] silly regex wonderings
Brought to you by:
agraef
From: Tim H. <q...@st...> - 2004-11-22 00:42:55
|
Hi, I'm playing around with regexes with a view to writing a module to perform wiki-style transformations on text.=20 So far, I've managed, with the help of TFM's `regsplit' example, to write a function that creates paragraphs based on \n\n in the document: | regsplit OPTS REGEX S =3D regex OPTS REGEX S regskip ++ [regskip]; |=20=20=20 | paragraphise S =3D map (tag "para") (regsplit "gn" "\n\n" S); However, I'm having a bad time trying to get my embolden function to work. It should be simple; anywhere you see a word surrounded by `*', replace it with "<bold>whatever</bold>" instead. Making this happen in Q seems to be rather a hassle, however. Currently, I've got: | embolden S =3D T if #T>0 | where T=3Dregex "gn" "(.+?)\\*(.+?)\\*(.+?)" S | (strcat [reg 1, | tag "bold" (reg 2), | reg 3]); | =3D S otherwise; |=20=20=20 | =3D=3D> embolden "this is some *bold* text, and behold, some *more* of= it" | ["this is some *bold* text, and behold, some <bold>more</bold>\n of it= "] ^^^^^^ oops, what happened here? Can anyone help me out with a function that gives the effect of a global substitution like I seem to be wanting? Ultimately I want to be writing=20 | wiki =3D paragraphise.embolden.italicise.handleHeadings or something similar. TIA, ~Tim =2D-=20 <http://spodzone.org.uk/> |