WG: Problems with regex

Joerg Fischer jf505 at gmx.de
Tue Mar 3 18:42:40 CET 2009


> which seems to work. My problem: how can I program a macro to remove the
> first 2 asterisks in a line?

I think the find pattern is ^\s*\*\*, which is to be replaced with an
empty string.

> My first shot
> 
> replace_in_selection("(^[ \\t]*[\*\*] ?)(.*$)", "\\2", "regex")
> 
> doesn't work. I don't have experiences with this function (what does
> "\\2" mean)?

\2 is matched string of the second parentheses, here .*$, which is the
rest of the line after the **. If you don't put the \* inside a
character class (inside the brackets) it will work.

Btw, macros can also be recorded. So, you could use the replace
dialog to type in the pattern (with less escaping) and record
and save the action. It's all pretty well documented in the online
help.

--Jörg


More information about the Discuss mailing list