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!
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

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
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,016
Messages
5,834,956
Members
430,330
Latest member
drAli77

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top