RegEx for matching “A-Z, a-z, 0-9, _” and “.”

后端 未结 5 2039
耶瑟儿~
耶瑟儿~ 2021-02-01 14:13

I need a regex which will allow only A-Z, a-z, 0-9, the _ character, and dot (.) in the input.

I tried:

[A-Za-z0-9_.] 

But, it did not

5条回答
  •  既然无缘
    2021-02-01 15:13

    Maybe, you need to specify more exactly what didn't work and in what environment you are.

    As to the claim that the dot is special in a charackter class, this is not true in every programming environment. For example the following perl script

    use warnings;
    use strict;
    
    my $str = '!!!.###';
    $str =~ s/[A-Za-z_.]/X/g;
    print "$str\n";
    

    produces

    !!!X###
    

提交回复
热议问题