Why does the dot character not work in this regular expression?

NET Regex. (ignoring)

I want it to fit

field_x_12
field_a_ABC
field_r_something

etc.

My question is: why the operator .does not work in this regex:

field_[.]_.*

but this (mostly equivalent) regular expression really works:

field_[a-z]_.*

Is there something that I am missing in the dot operator .?

+3
source share
5 answers

A .inside the character class ( [...]) is a literal dot character. If you want it to act as a wildcard, do not use parentheses.

+6
source

[.]? [] , . - , RegEx.

field_._.*

.

. - .NET RegEx.

+1

Inside the brackets .is a literal dot and does not match the character.

0
source

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

0
source

When it is inside a character class, a period is just a period, not a wildcard.

0
source

Source: https://habr.com/ru/post/1760630/


All Articles