views:

46

answers:

5

Hello I have a .NET Regex. (with ignore-case)

I want it to match

field_x_12
field_a_ABC
field_r_something

etc

My question is why the . operator doesn't work in this regex:

field_[.]_.*

yet this (equivalent basically) regex does work:

field_[a-z]_.*

Is there something I'm missing about the dot operator . ?

+5  A: 

A . inside a character class ([...]) is a literal dot character. If you want it to act as a wildcard, don't use the brackets.

Daniel Vandersluis
so what you really want is field_._.* (assuming you want a single match-all char instead of only a-z)
Crayon Violent
+1  A: 

Why are you using [.]? The [] denotes a explicit set of characters, so the . character is what the RegEx is looking for.

field_._.*

Should work fine.

See this handy .NET RegEx cheat sheet.

Oded
A: 

Inside brackets . is a literal dot and doesn't match any character.

jwsample
A: 

You should try field_._.* because inside the [] it is treatd as an acutal dot.

Jerod Houghtelling
A: 

When it's inside a character class, the dot is just a period, not a wildcard.

Toby