Testing often encounter the processing of data, such as I want to delete some specific data, the data source is fetched from the Web request, this time may be copied down a lot of content, where we only need certain parts, the author is usually copied to notepad++ processing, combined with regtester tools, But regtest need to export matching data, not directly copied, a little bit of trouble ... So I want to use VBA to write a regular expression extraction tool, and do not take the time. (Halo, just think of actually there will be online tools, such as: http://tool.oschina.net/regex/), although found online tools, or to say that you do this bar ~ ~ ~
1, the first is the interface design, very clear
An original text box, a regular expression input box, an extract text display box, and an execution button.
2, the program entrance
Because it is a single gadget, for simplicity, do not do add-ins or ribbon, directly save a XLA, when the file opens the user form display, the form closed, close the file, to achieve a closed loop.
(1) Open file startup UserForm
Private Sub Workbook_Open ()
Application.wait now () + timeserial (0, 0, 1)
Reggetfrm.show 0
End Sub
(2) Close the file when UserForm is closed
Private Sub userform_queryclose (Cancel As Integer, Closemode as Integer)
Thisworkbook.close
End Sub
3, extract text implementation, using VBScript.RegExp object, achieve the basic matching, and then the stitching text
Set regex = CreateObject ("VBScript.RegExp")
With regex
. Pattern = Mypattern
. Global = True
. IgnoreCase = False
Set matchs =. Execute (Origitext)
End with
For each m in Matchs
Txttarget.text = txttarget.text + M + Chr (10)
Next
Exit Sub
4, the following, put in the network disk, the students need to download to play, Link: https://pan.baidu.com/s/1V2O4kd-Jl-mkiHyJMD93Gg Password: 1ily
Using VBA to make a regular expression extraction text tool