Matching \code{foo}
Posted: Tue Feb 12, 2008 9:10 am
Hi all,
My current project requires me to parse text for things like \foo{bar} and for most things I have a pattern that works, for example to match \emph{text here} I use ~\\\emph\s*{([^}]+)}~ and that works, as it does with many others.
For some of the patterns though I have to include brackets, for example to when trying to match \reservedword{foobar} it would only match when my pattern had brackets round reservedword e.g ~\\\(reservedword)\s*{([^}]+)}~, I don't know if a similar reason is behind my current problem or not, even if it isn't I wouldn't mind somebody explaining why that worked but ~\\\reservedword\s*{([^}]+)}~ didn't.
My current problem is that \code{foobar} isn't being matched with either of the above techniques, both ~\\\code\s*{([^}]+)}~ and ~\\\(code)\s*{([^}]+)}~ don't match it, does anybody either (a) no why or (b) no of a pattern to match it?
Basically I need to match \code followed by a { followed by any character other than } which closes the definition.
Thanks in advance for any help you may be able to offer me,
Tom
My current project requires me to parse text for things like \foo{bar} and for most things I have a pattern that works, for example to match \emph{text here} I use ~\\\emph\s*{([^}]+)}~ and that works, as it does with many others.
For some of the patterns though I have to include brackets, for example to when trying to match \reservedword{foobar} it would only match when my pattern had brackets round reservedword e.g ~\\\(reservedword)\s*{([^}]+)}~, I don't know if a similar reason is behind my current problem or not, even if it isn't I wouldn't mind somebody explaining why that worked but ~\\\reservedword\s*{([^}]+)}~ didn't.
My current problem is that \code{foobar} isn't being matched with either of the above techniques, both ~\\\code\s*{([^}]+)}~ and ~\\\(code)\s*{([^}]+)}~ don't match it, does anybody either (a) no why or (b) no of a pattern to match it?
Basically I need to match \code followed by a { followed by any character other than } which closes the definition.
Thanks in advance for any help you may be able to offer me,
Tom