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

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
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).
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,213,482
Messages
6,113,916
Members
448,533
Latest member
thietbibeboiwasaco

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
Back
Top