Split string and trim every element

后端 未结 5 946
失恋的感觉
失恋的感觉 2021-02-01 14:39

Is there any library API or regex pattern to split a String on some delimiter and automatically trim leading and trailing spaces from every element without having to loop the el

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-01 15:22

    Edited to correct whitespace error that was pointed out by Marcus.

    I think that the proper regex should be [\s]*#[\s]*:

    str.split("[\\s]*#[\\s]*");
    

    Tested on : http://regexpal.com/

提交回复
热议问题