I need help creating a JavaScript regex that can match strings like the examples provided. The string may have whitespace at the front, back, or both but not within the string itself.
Examples:
'Z5LW-KRT2' MATCH
' Z5LW-krt2' MATCH
'Z5LW-KRT2 ' MATCH
' Z5LW-KRT2 ' MATCH
' Z5LW-K RT2 ' NO MATCH
Currently, I have a regex pattern that matches strings without any whitespace anywhere. However, I'm struggling to modify it to include whitespace at the beginning or end but exclude it within the string as shown in the examples.
^[A-Za-z0-9\-]+$