How to write regular expression to match only numbers, letters and dashes?

前端 未结 3 1164
太阳男子
太阳男子 2021-01-22 10:12

I need an expression that will only accept:

  • numbers
  • normal letters (no special characters)
  • -

Spaces are not allowed either.<

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-22 10:20

    This is a community wiki, an attempt to compile links to related questions about this "URL/SEO slugging" topic. Community is invited to contribute.

    Related questions

    • regex/php: how can I convert 2+ dashes to singles and remove all dashes at the beginning and end of a string?
      • -this--is---a-test-- becomes this-is-a-test
    • Regex for [a-zA-Z0-9-] with dashes allowed in between but not at the start or end
      • allow spam123-spam-eggs-eggs1 reject eggs1-, -spam123, spam--spam
    • Translate “Lorem 3 ipsum dolor sit amet” into SEO friendly “Lorem-3-ipsum-dolor-sit-amet” in Java?

    Related tags

    • [slug]

提交回复
热议问题