vendredi 8 mai 2015

Regex for non-alphanumeric delimiters (not \W)

I have probably completely missed something, but here is what I have:

  1. -- Need to prevent inadvertent release of phone numbers.
  2. -- all numbers in the form nnn-nnnn
  3. -- may or may not be delimited (e.g, tab, comma, space, whatever)
  4. -- do NOT block journal articles or study numbers having similar (but not identical) form -- for example xxxnnn-nnnnxxx (yeah, sort of contradicts 'delimited', but "x" are alphanumeric only )

So, I have

(\A|\s|\W)\d{3}-\d{4}(\Z|\s|\W)

Which works! Almost the way I want. Almost. However, \W is ^a-zA-Z0-9_ and _ is a potential delimiter. Already tried replacing \W with ^a-zA-Z0-9 with no success (actually, worse), but perhaps specified improperly? FWIW, this will be evaluated by .NET engine.

Aucun commentaire:

Enregistrer un commentaire