Jump to content
Sign in to follow this  
xcaliber13

Text extraction help

Recommended Posts

xcaliber13

I am looking for a way to extract text from a file and create a new file with the extracted text. Along with the extracted text no longer in the original file.

Example text:

H   SMUC text text text text text

1 more text more text more text

2 more text

3 more text

4 more text

5  more text

H SMUCP text text text text text

1 more text more text more text

2 more text

3 more text

4 more text

5  more text

repeats to end of file.

I want to extract all text from H SMUCP to end of line 5.

I have tried

#include <Date.au3>
#include <MsgBoxConstants.au3>
#include <Array.au3>
#include <File.au3>
#include <String.au3>
#include <StringConstants.au3>

Global $sFile

$selectedfolder = "X:\DEMOS\SRA\SMATemp"
$aFileList = _FileListToArray($selectedfolder, "*.txt", $FLTA_FILES)


For $i = 1 To $aFileList[0]
$afilename = StringMid($aFileList[$i], 52, 11)
$tFile = FileRead("X:\DEMOS\SRA\SMATemp\"&$aFileList[$i])

Local $bResults[0]

$bResults = StringRegExp($tFile, "(H   SMUCP*)\5  ", 3)

_ArrayDisplay($bResults)

Next
Edited by xcaliber13
title correction

Share this post


Link to post
Share on other sites
xcaliber13

mikell,

         Just had to change to this:

$aResults = StringRegExp($tFile, "(H\h+SMUCP.+\R+(?:.+\R*){5})", 3)

And then it pulled the correct data.

Thank you

Regex will be the death of me yet.

Again Thank you

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.