Regexp: Trim parts of a string and return what ever is left

一个人想着一个人 提交于 2019-12-04 17:43:52

Try this:

var trimmed = /#(.*)$/.exec('12344dfdfsss#isa')[1];

You can use also use match to match a string against a regex, and then extract the first subexpression that matched using [1]:

var trimmed = '12344dfdfsss#isa'.match(/#(.*)$/)[1]

if it's possible that the subject string could have more than one # then consider:

/#(.*)$/

captures everything that follows the first # in the subject string., while

/#(.*?)$/

captures what follows the last.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!