RegEx for no whitespace at the beginning and end

后端 未结 14 1180
傲寒
傲寒 2020-11-27 07:20

I want to design an expression for not allowing whitespace at the beginning and at the end of a string, but allowing in the middle of the string.

The regex I\'ve tri

14条回答
  •  误落风尘
    2020-11-27 07:28

    ^[^\s].+[^\s]$
    

    That's it!!!! it allows any string that contains any caracter (a part from \n) without whitespace at the beginning or end; in case you want \n in the middle there is an option s that you have to replace .+ by [.\n]+

提交回复
热议问题