CQDJYUHONG 2012-01-08
代码如下:
interface IRegExp2 : IDispatch { [id(0x00002711), propget] HRESULT Pattern([out, retval] BSTR* pPattern); [id(0x00002711), propput] HRESULT Pattern([in] BSTR pPattern); [id(0x00002712), propget] HRESULT IgnoreCase([out, retval] VARIANT_BOOL* pIgnoreCase); [id(0x00002712), propput] HRESULT IgnoreCase([in] VARIANT_BOOL pIgnoreCase); [id(0x00002713), propget] HRESULT Global([out, retval] VARIANT_BOOL* pGlobal); [id(0x00002713), propput] HRESULT Global([in] VARIANT_BOOL pGlobal); [id(0x00002717), propget] HRESULT Multiline([out, retval] VARIANT_BOOL* pMultiline); [id(0x00002717), propput] HRESULT Multiline([in] VARIANT_BOOL pMultiline); [id(0x00002714)] HRESULT Execute( [in] BSTR sourceString, [out, retval] IDispatch** ppMatches); [id(0x00002715)] HRESULT Test( [in] BSTR sourceString, [out, retval] VARIANT_BOOL* pMatch); [id(0x00002716)] HRESULT Replace( [in] BSTR sourceString, [in] VARIANT replaceVar, [out, retval] BSTR* pDestString); };
代码如下:
'Author: Demon 'Link: http://demon.tw/programming/vbs-regexp-object.html 'Date: 2011/12/26 Dim fso, regex, str Set fso = CreateObject("Scripting.FileSystemObject") Set regex = CreateObject("VBScript.RegExp") str = fso.OpenTextFile("demon.txt").ReadAll regex.Global = True regex.MultiLine = True regex.Pattern = "^\s*\n" str = regex.Replace(str, "") '相当于JavaScript中的 str = str.replace(/^\s*\n/gm, "") fso.OpenTextFile("demon.txt", 2).Write str