[Tutor] Regular expression to match \f in groff input?

Danny Yoo dyoo at cs.wpi.edu
Thu Aug 21 20:12:04 CEST 2008


On Thu, Aug 21, 2008 at 1:40 PM, Bill Campbell <bill at celestial.net> wrote:
> I've been beating my head against the wall try to figure out how
> to get regular expressions to match the font change sequences in
> *roff input (e.g. \fB for bold, \fP to revert to previous font).
> The re library maps r'\f' to the single form-feed character (as
> it does other common single-character sequences like
r'\n').


Does this example help?

###########################################
>>> sampleText = r"\This\ has \backslashes\."
>>> print sampleText
\This\ has \backslashes\.
>>> import re
>>> re.findall(r"\\\w+\\", sampleText)
['\\This\\', '\\backslashes\\']
###########################################


More information about the Tutor mailing list