Pattern matching in VBE replace

Zauberkind
2StarLounger
Posts: 141
Joined: 21 Oct 2011, 10:08

Pattern matching in VBE replace

Post by Zauberkind »

Greetings,
The VBE code editor allows search-and-replace with pattern matching.
I can't find any documention on the regular expressions allowed.
Finding xx? works; finding xx(?) doesn't. Replace expressions with \1 etc. also don't work as expected.
Is there any documentation? Anywhere?
Inquiring minds want to know.
Regards,
ZK

User avatar
HansV
Administrator
Posts: 78537
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Pattern matching in VBE replace

Post by HansV »

I think there was some documentation in the VBA help in earlier versions, but if it's still there it has become virtually impossible to find (like so much else).
Anyway, it's a fairly basic (excuse the pun) implementation of wildcards, it doesn't offer the power and flexibility of regular expressions.

? = any single character
* = any number of characters
[a-k] = any of the characters from a to k
[!a-k] = any character not in the range a...k
Best wishes,
Hans

Zauberkind
2StarLounger
Posts: 141
Joined: 21 Oct 2011, 10:08

Re: Pattern matching in VBE replace

Post by Zauberkind »

Does that mean wildcard replace doesn't work?

User avatar
HansV
Administrator
Posts: 78537
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Pattern matching in VBE replace

Post by HansV »

As far as I know, you can only use wildcards in the Find What box, not in the Replace With box.

If you want more advanced options, you can copy your code into Word, which has some support for regular expressions, then after processing the text, copy it back into the VBE.
Or use an editor such as NotePad++ (free).
Best wishes,
Hans

Zauberkind
2StarLounger
Posts: 141
Joined: 21 Oct 2011, 10:08

Re: Pattern matching in VBE replace

Post by Zauberkind »

I guess you're right about the Replace With box. How sad!

Doing the deed in Word works, but it's a major PITA! C'est la vie.

Thanks for the info.

ZK