regex request

M

mike.spiller

I need to come up with a regex routine that will extract some data
from a file, and I am admittedly lousy with regexes.

The file contents are as such. Either there will be a single entry
such as...
***********************************************
(header info)
1:
Some data (multiline)

-or-

(header info)
1:
Some data (multiline)
2:
More data
etc...
*************************************************
I need to extract just the data in the "1:" section. Can anyone help?
 
D

Doug Robbins - Word MVP

I guess by regex you mean macro and that you want the macro to do this on a
group of files.

Need to know exactly how your documents are arranged and also what is to be
done with the extracted information.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
M

mike.spiller

There is a folder of address files. I will select one at a time via a
filedialog box.
The files look like this. I just need the text after "1:" , i.e.
123 First St.
Seattle, WA
98333,
even if there are several entries.

************************** EXAMPLE ***********************
[ addresses ]

1:
123 First St.
Seattle, WA
98333

**************** OR *******************

[addresses]

1:
123 First St.
Seattle, WA
98333

2:
PO Box 111
Seattle, WA
98114

************************ END ************************
 
D

Doug Robbins - Word MVP

With a little bit more information, it would be possible to create a macro
that will go through each file in the folder and extract the first address
from each.

If you open a file and click on the show hide button, does it look like
this:

[addresses]¶

1:¶
123 First St.¶
Seattle, WA¶
98333¶

2:¶
PO Box 111¶
Seattle, WA¶
98114¶

Then, what do you want to do with the

123 First St.
Seattle, WA
98333

When it has been extracted?

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
M

mike.spiller

With a little bit more information, it would be possible to create a macro
that will go through each file in the folder and extract the first address
from each.

If you open a file and click on the show hide button, does it look like
this:

[addresses]¶

1:¶
123 First St.¶
Seattle, WA¶
98333¶

2:¶
PO Box 111¶
Seattle, WA¶
98114¶

Then, what do you want to do with the

123 First St.
Seattle, WA
98333

When it has been extracted?

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP




There is a folder of address files. I will select one at a time via a
filedialog box.
The files look like this. I just need the text after "1:" , i.e.
123 First St.
Seattle, WA
98333,
even if there are several entries.
************************** EXAMPLE ***********************
[ addresses ]
1:
123 First St.
Seattle, WA
98333
**************** OR *******************
[addresses]

1:
123 First St.
Seattle, WA
98333
2:
PO Box 111
Seattle, WA
98114
************************ END ************************- Hide quoted text-

- Show quoted text -

I will eventually be taking that text, and put it into a visio shape.
 
D

Doug Robbins - Word MVP

Is:

- Show quoted text -

the answer to the first question?

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

With a little bit more information, it would be possible to create a macro
that will go through each file in the folder and extract the first address
from each.

If you open a file and click on the show hide button, does it look like
this:

[addresses]¶

1:¶
123 First St.¶
Seattle, WA¶
98333¶

2:¶
PO Box 111¶
Seattle, WA¶
98114¶

Then, what do you want to do with the

123 First St.
Seattle, WA
98333

When it has been extracted?

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP




There is a folder of address files. I will select one at a time via a
filedialog box.
The files look like this. I just need the text after "1:" , i.e.
123 First St.
Seattle, WA
98333,
even if there are several entries.
************************** EXAMPLE ***********************
[ addresses ]
1:
123 First St.
Seattle, WA
98333
**************** OR *******************
[addresses]

1:
123 First St.
Seattle, WA
98333
2:
PO Box 111
Seattle, WA
98114
************************ END ************************- Hide quoted
text -

- Show quoted text -

I will eventually be taking that text, and put it into a visio shape.
 
M

mike.spiller

Is:

- Show quoted text -

the answer to the first question?

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP


With a little bit more information, it would be possible to create a macro
that will go through each file in the folder and extract the first address
from each.
If you open a file and click on the show hide button, does it look like
this:
[addresses]¶

1:¶
123 First St.¶
Seattle, WA¶
98333¶

2:¶
PO Box 111¶
Seattle, WA¶
98114¶
Then, what do you want to do with the
123 First St.
Seattle, WA
98333
When it has been extracted?
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP
There is a folder of address files. I will select one at a time via a
filedialog box.
The files look like this. I just need the text after "1:" , i.e.
123 First St.
Seattle, WA
98333,
even if there are several entries.
************************** EXAMPLE ***********************
[ addresses ]
1:
123 First St.
Seattle, WA
98333
**************** OR *******************
[addresses]
1:
123 First St.
Seattle, WA
98333
2:
PO Box 111
Seattle, WA
98114
************************ END ************************- Hide quoted
text -
- Show quoted text -

I will eventually be taking that text, and put it into a visio shape.- Hide quoted text -

- Show quoted text -

Yes, the plan is to extract the address out of a file and have it end
up in a Visio flowchart shape.
 
R

Russ

Mike,
This is the first question that Doug is waiting for you to answer.

Quote:

If you open a file and click on the show hide button, does it look like
this:

[addresses]¶

1:¶
123 First St.¶
Seattle, WA¶
98333¶

2:¶
PO Box 111¶
Seattle, WA¶
98114¶

Unquote:
 
M

mike.spiller

Mike,
This is the first question that Doug is waiting for you to answer.

Quote:

If you open a file and click on the show hide button, does it look like
this:

[addresses]¶

1:¶
123 First St.¶
Seattle, WA¶
98333¶

2:¶
PO Box 111¶
Seattle, WA¶
98114¶

Unquote:

yes, that's exactly how it looks.
 
D

Doug Robbins - Word MVP

The following code will extract the first address from all of the documents
in a folder (if each document is formatted as you indicated and it will
insert them into a new file. You will have to come up with your own code
for the Visio part of it.

Dim MyPath As String
Dim MyName As String
Dim source As Document, target As Document
Dim addr As Range
Dim i As Long
'Create a new document to contain the addresses
Set target = Documents.Add
'let user select a path
With Dialogs(wdDialogCopyFile)
If .Display() <> -1 Then Exit Sub
MyPath = .Directory
End With
'strip quotation marks from path
If Len(MyPath) = 0 Then Exit Sub
If Asc(MyPath) = 34 Then
MyPath = Mid$(MyPath, 2, Len(MyPath) - 2)
End If
'get files from the selected path
'and extract the first address
'and insert it into the target document
MyName = Dir$(MyPath & "*.*")
Do While MyName <> ""
Set source = Documents.Open(MyName)
i = 1
With source
Set addr = .Paragraphs(4).Range
While Len(.Paragraphs(4 + i).Range) > 1
addr.End = .Paragraphs(4 + i).Range.End
i = i + 1
Wend
End With
target.Range.InsertAfter addr & vbCr
source.Close wdDoNotSaveChanges
Loop


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Mike,
This is the first question that Doug is waiting for you to answer.

Quote:

If you open a file and click on the show hide button, does it look like
this:

[addresses]¶

1:¶
123 First St.¶
Seattle, WA¶
98333¶

2:¶
PO Box 111¶
Seattle, WA¶
98114¶

Unquote:

yes, that's exactly how it looks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top