Regexp:修剪字符串的一部分并返回剩下的内容 [英] Regexp: Trim parts of a string and return what ever is left
本文介绍了Regexp:修剪字符串的一部分并返回剩下的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图使用正则表达式来获取我的字符串12344dfdfsss #isa中的#背后的任何内容,在这种情况下,我想从字符串中获取'isa'。
Im trying to use regexp to get whatever's behind the # in my string "12344dfdfsss#isa", in this case I wanna get the 'isa' out of the string.
我找到了这些答案(如何使用RegExp删除大字符串中的一小部分字符串)很有帮助,但它返回的全部都是'true'。
I found these answers (How to remove a small part of the string in the big string using RegExp) helpful, but all it returns is 'true'.
var myString = '12344dfdfsss#isa',
newRG = new RegExp('#(.*)$'),
trimmed = newTrim.test(myString);
我希望它重新调整'isa'而不是真的。
I want it to retun 'isa' and not true.
感谢您的帮助
//我
Thanks for any help // I
推荐答案
试试这个:
var trimmed = /#(.*)$/.exec('12344dfdfsss#isa')[1];
这篇关于Regexp:修剪字符串的一部分并返回剩下的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文