Q:

How to write output file after all regexp match?

I have text file containing line starts with mmrk.
I want to extract all lines and write output.
I am trying following code. (I know this is not correct method, Just to show what I want.)
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Dim fso, MyFile, FileName, Text
dim oFile, strPath
Set fso = CreateObject("Scripting.FileSystemObject")
FileName = "C:\Users\user\Desktop\2.rtf"
strPath = "C:\Users\user\Desktop\1.txt"
Set MyFile = fso.OpenTextFile(FileName, ForReading)
Do While MyFile.AtEndOfStream <> True
    Text = MyFile.ReadAll
Loop
Set regEx_ = new regExp
With regEx_
 .Global = True
 .MultiLine = True
 .IgnoreCase = True

 'Do some regex find and replace(works perfectly)

 .Pattern = "mmrk.*"
    If regEx_.Test(Text) Then
    Set oFile = fso.OpenTextFile(strPath, 2, True, -1)
      oFile.Write Text
      oFile.Close
    End If
End With
MyFile.Close

Edit
I need to get lines from string.
I am currently first saving temp file from string and use Nefariis's answer to do the rest. Is there any direct method.

A:

I think there are easier ways of doing this that do not involve a regex.
In VBScript:
FileName = "C:\Users\user\Desktop\2.rtf"
strPath = "C:\Users\user\Desktop\1.txt"

Set inFile = CreateObject("Scripting.FileSystemObject").OpenTextFile(FileName)
Set outFile = CreateObject("Scripting.FileSystemObject").CreateTextFile(strPath,True)

Do Until inFile.AtEndOfStream
    Dim line : line = inFile.Readline
    If inStr(line, "mmrk.") = 1 then outFile.writeLine(line)
Loop

inFile.Close
outFile.Close

In VB.Net
Dim inFile as String() = File.ReadAllLines("inFileName")
Dim sw As StreamWriter = New StreamWriter("OutFileName", True)

For Each line As String In inFile
    If line.StartsWith("mmrk.") Then sw.WriteLine(line)
Next

sw.Close()

This reads the file in, then goes through it looking for lines the start with "mmrk.", and saves the line into a seperate text file that you specifiy. 

