使用正则表达式查找和替换字符串

时间:2011-06-27 10:38:03

标签: regex

我需要找到

sessionOpen(0, (int *)(&SessionId));

并替换如下,

sessionOpen(
\#if USE_MULTIPLE_DB
              0,
\#endif
 (int *)(&SessionId));

如何使用正则表达式搜索和替换方法实现这一点????

2 个答案:

答案 0 :(得分:1)

替换sessionOpen\((0), \(int \*\)\(&SessionId\)\);

sessionOpen(\n#if USE_MULTIPLE_DB $1, #endif\n(int *)(&SessionId))

(我假设您要捕获零0

答案 1 :(得分:-1)

这会对您有所帮助:http://gaoithe.blogspot.com/2009/11/eclipse-regexp-findreplace-error.html

Make sure everything is dos2unix converted if touched by something which converts it the other way. In eclipse you can select File -> Convert line delimiters to ...

WARNING: Don't mess with file encoding unless you know what you'er doing!
In eclipse these other settings are relevant:

 Right-click on Project -> Properties
    Resource -> Text File Encoding
      Might be best to leave this (Inherited from container Cp1252 for windows)

    Resource -> New Text File Line Delimiter
      Change to "unix"
 Windows -> Preferences
    General -> Editors -> Text Editors
      Select "Insert spaces for tabs"
    General -> Content types -> Text -> Tcl Content Type

Set default enccoding (leave it alone is probably best policy!)