Trim spaces from start and end of string

前端 未结 14 1498
情歌与酒
情歌与酒 2020-11-28 01:56

I am trying to find a way to trim spaces from the start and end of the title string. I was using this, but it doesn\'t seem to be working:

title = title.repl         


        
14条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-28 02:38

    Here is my current code, the 2nd line works if I comment the 3rd line, but don't work if I leave it how it is.

    var page_title = $(this).val().replace(/[^a-zA-Z0-9\s]/g, '');
    page_title = page_title.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
    page_title = page_title.replace(/([\s]+)/g, '-');
    

提交回复
热议问题