views:

92

answers:

1

I'm in the process of converting some LaTeX documentation to restructured text and having some trouble with a regular expression in Visual Studio 2003. I'm trying to convert \emph{text} to *text* using the following find/replace strings:

\\emph\{([^\}]*)\} 

*\0*

However, using this pair I get \emph{text} converted to *\emph{text}* which was not what I expected. When I use *\1* instead of *\0* I get ** as the replacement result.

What am I missing or what don't I understand about the grouping rules?

Thanks.

+2  A: 

I think that in the VS regex replacement syntax, \0 is the whole matched string, while \1 is the content of the first captured variable (\2 being the second and so on). Therefore:

\0

However, using this pair I get \emph{text} converted to *\emph{text}* which was not what I expected.

Thus confirming, \0 is the whole matched string.

When I use *\1* instead of *\0* I get ** as the replacement result.

Probably you are not matching anything in the capture class.

To add more detail, the syntax for defined a capture class (called a tagged expression in the docs) uses the braces {}, not parentheses () as you are using here. Probably this will work as the "find" expression:

\\emph\{{[^\}]*}\}
1800 INFORMATION
Ah... that is exactly the problem. Thank you very much.
Joe Corkery