Using VBA to make a regular expression extraction text tool

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.