Negative regrex [field] comparison in Logstash

Hi,
I'm trying to achieve simple [username] field character cheks.
If [username] field NOT consists of [A-Za-z] then add new field. For example, if [username] equals foo.foo then write it into separate field.

I can't figure out why the code below in my case not working:

if [username] !~ /^[A-Za-z]+/ {
    mutate { add_field => { "username_invalid" => "%{username}" } }
}

Thanks in advance for the hint.
logstash 7.9

I forgot to add $ to the end of /^[A-Za-z]+/.
The correct regrex is /^[A-Za-z]+$/.

Your regex is never going to be false, cause if you have a username "foo.bar", the regex is detecting the word "foo" as true", complete it with the end line char ^[A-Za-z]+$

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.