Sachin
Sachin

Reputation: 69

Need Help For VBScript Regex

I wannt to build VbScript regex for string having format like

XX-XX-XX-XX
XX= \w (Alphanumeric)
Note : Number of Hyphen are dynamic.

Sample i/p ABSCD123 ABC-123 ABC-234-PQ3 A-B-C

I created something like

^\w+\-*\w+$

But it is not working.Can anybody help me?

Upvotes: 0

Views: 58

Answers (1)

juharr
juharr

Reputation: 32266

I think you want to group the first "word" with the hyphen

^(\w+\-)*\w+$

This assumes that you want to match things like

XX-XX
XXX-X
XX-XX-XX-XX-XX-XX-XX-XX
XXX

But not

XX-
XX--XX

If there has to be a hyphen then this would work

^(\w+\-)+\w+$

Upvotes: 1

Related Questions