Remove spaces from the beginning and end of a string

后端 未结 2 1153
小蘑菇
小蘑菇 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:11

    If it's only white-space, why not just use trim()?

    0 讨论(0)
  • 2021-01-07 18:28

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

    ((?=^)(\s*))|((\s*)(?>$))
    
    0 讨论(0)
提交回复
热议问题