Regular expressions - pattern with "

Spurious

Active Member
Joined
Dec 14, 2010
Messages
439
Hey guys,

I got a question regarding regular expressions, I got the following code:

Code:
.Pattern = "<a href=\" / (\w+) \">"

I get a compile error for \w+, it says expected: expression.

And what do I have to change \w+ to in order to use only digits and letters?

Thanks in advance!
 

Some videos you may like

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
Here:

Code:
.Pattern = "<a href=\" & Chr$(34) & " / (\w+) \" & Chr$(34) & ">"
 
Last edited:

Spurious

Active Member
Joined
Dec 14, 2010
Messages
439
I got one more question regarding my pattern.

Currently I use \w, but I want the pattern to contain at least one digit and preferably only digits and letters (\w also contains _ and maybe something else).
 

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
You could use:

[0-9a-z]+

to specify that only alphanumeric characters are to be included. Note that I don't think it will be easy to specify at least one numeric character (could be wrong) but I think in a regex pattern you would need conditions which are not supported in VBA's flavour of regexp.

You could subsequently check that the matching string does indeed contain at least one digit - you could use regular VBA for this eg:

If Somestring Like "*#*" Then '# here means a numeric character

'it's OK

Else

'it ain't OK

End if
 

Watch MrExcel Video

Forum statistics

Threads
1,108,992
Messages
5,526,109
Members
409,685
Latest member
Bellybb

This Week's Hot Topics

Top