[Webinar] Learn how to a build a cloud-first strategyRegister Now


VBScript - Find text in a txt file using regular expressions and write to another output file

Posted on 2006-05-01
Medium Priority
Last Modified: 2008-01-09
Good afternoon,

I am looking for a way in a VBScript to find text based on a regular expression search pattern and write that output to another file (taking into account that the search pattern may need to return more than one result).  I have found a lot of resources on replacing text strings in a txt file which is fairly simple but little on selecting text in a file based on a regular expression, capturing it as a string, and writting this string to another output file.  Any links or code examples would be appreciated.  I am executing this from a batch file with the cscript command line utility.

Question by:orionpm

Accepted Solution

Clever_Bob earned 2000 total points
ID: 16583502
I can give you some guidance anyway and I hope this helps point you in the right direction.

1) Your VBScript code needs to declare the filesystem object
2) point the filesystem object in the direction of your text file
3) read the contents of the text file into a local variable
4) make the changes using the 'replace' command or grab the text you need using 'instr' and a combination of string manipulation commands (left, mid etc)
5) write the variables to your new text file using the filesystem object again
6) close the filesystem object

Hope this helps!

Author Comment

ID: 16587510
Thanks, the issue I was having was grabbing the text I read using regular expressions.  After sifting through the Micorosoft documentation on this I am able to pass my regular expression in as an argument from the command line which is working great.  

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Starting up a Project

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question