1

This regex lets me have a string with alphanumeric, dash, underscore, and space chars in my string:

^[a-zA-Z0-9-_ ]+$

However, I need it to prevent string starting and ending by space. How can I do it?

ypwtcetr
  • 41
  • 3
  • The answers are [here](https://stackoverflow.com/questions/34974942/regex-for-no-whitespace-at-the-beginning-and-end). Also, a tip: always put `-` inside character classes at the start or end to avoid weird issues, especially in PHP regex. – Wiktor Stribiżew Mar 12 '20 at 13:47

0 Answers0