Remove spaces from the beginning and end of a string

后端 未结 2 1177
小蘑菇
小蘑菇 2021-01-07 17:44

I am pretty new to regular expressions. I need to clean up a search string from spaces at the beginning and the end. Example: \" search string \" Result: \"search string\"

2条回答
  •  余生分开走
    2021-01-07 18:28

    Yep, you should use trim() I guess.. But if you really want that regex, here it is:

    ((?=^)(\s*))|((\s*)(?>$))
    

提交回复
热议问题