0

I have the following Regular Expression in VB.NET which works just fine.

(Istr_)*(8[25]\d{5}[0-9xX]{2}|DR\d{5}[0-9xX]{2}|R\d{2}-\d{4})

However, I want the "Istr_" part only to be case-insensitive, while the rest of the expression remains case-sensitive. I attempted that by simply adding "?i:" according to the MSDN documentation like so:

(?i:Istr_)*(8[25]\d{5}[0-9xX]{2}|DR\d{5}[0-9xX]{2}|R\d{2}-\d{4})

But this breaks the RegularExpressionValidator in my form.

Does the * have something to do with this? I'm not sure is the appropriate character to join the patterns. I want the first pattern to be an optional case-insensitive prefix to the second pattern.

Furthermore, I don't want to allow spaces, which I haven't been able to figure out how to do yet.

Thanks. :)

Chiramisu
  • 4,687
  • 7
  • 47
  • 77

1 Answers1

4

See the discussion here: Can you make just part of a regex case-insensitive?

Or make a not very beautiful solution, but works:

([Ii][Ss][Tt][Rr]_)?(8[25]\d{5}[0-9xX]{2}|DR\d{5}[0-9xX]{2}|R\d{2}-\d{4})

I've changed your * to ?. This means:

?: the prefix iStR_ is optional
*: the prefix IStr_ is optional but can occur multiple times
Community
  • 1
  • 1
Philipp
  • 4,645
  • 3
  • 47
  • 80
  • What about my `*` is that the right character for what I want to accomplish with the joining? Also, how do I disallow spaces? And I already read that question and didn't like the solution. Thanks. – Chiramisu Aug 29 '12 at 19:44
  • 1
    As @FiveO stated, `?` means "0 or 1 times", `*` means "0 or more times". It sounds like `?` is what you want. And you are kind of stuck since javascript simply does not support changing the match mode inline. – latkin Aug 29 '12 at 20:04
  • Thank you both for your comments. :) – Chiramisu Aug 30 '12 at 00:14