regular expression doesn't detect set pattern

M

muyBN

I've got the following code in which I'm trying to use regular expressions:

'at top of module:
Dim Reg As RegExp

'in procedure:
Set Reg = New RegExp

Reg.Pattern = "\n"
With Selection
.MoveDown unit:=wdParagraph, Extend:=wdExtend
If InStr(LCase(Selection), "address") = 0 Then
If Selection <> Reg.Pattern Then .MoveDown unit:=wdParagraph,
Extend:=wdExtend
End If

The selected text is a paragraph mark yet the macro still moves down and
selects the next paragraph (meaning that it detects the original paragraph
mark as not being a paragraph mark). Where am I going wrong? I thought the \n
criteria was supposed to represent any type of line break.
 
R

Russ

I believe you are using a VBScripting object to do regular expressions. You
might find more help on that in a different forum for VBScripting. Word VBA
and Microsoft Windows don't do Regular Expression natively and most people
in this forum just use the Word VBA wildcards to search within their
documents.

See this link for initial information on RegExp
http://tinyurl.com/2yb5o7
 
B

Bryan

Thanks for the suggestion, Russ. For searching, I use wildcards also but I
would like to use regular expressions since they're better for evaluating
(not searching for) text so that I don't have to do something like

If Selection=chr(13) or selection=chr(10)

if I don't know if the end-of-line character will be a soft or hard break. I
would prefer to take advantage of pattern matching rather than a specific
character. I've never been successful, for example, in writing

if selection="^p"

but I use ^p all the time for searching. If you know of a better way for
evaluating a selection, I'll readily welcome the suggestion.
 

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