regexsedcharacter-class

sed: -e expression #1, char 52: Invalid range end


I have this regex expression that validates on regex101: [a-zA-Z0-9-_.]+\@[a-zA-Z0-9-]+\.+[a-zA-Z0-9-]{2,4}

But when I try to run it with sed I get: sed: -e expression #1, char 52: Invalid range end

As far as I understand this is normally a problem when you define your range like: A-z in some versions of sed, but here I'm putting a-zA-Z? So I guess it's the special chars causing the error, but how do I solve it?

Sed: $( sed -E -n '/[a-zA-Z0-9-_.]+\@[a-zA-Z0-9-]+\.+[a-zA-Z0-9-]{2,4}/p' < emails.txt )


Solution

  • In your first character class [a-zA-Z0-9-_.] this is no valid range: 9-_

    Move - to last character in your character class: [a-zA-Z0-9_.-]