我的程序中有如下字符串:
var myStrings = [
"[asdf] thisIsTheText",
"[qwerty] andSomeMoreText",
"noBracketsSometimes",
"[12345]someText"
];
我想捕获字符串“thisIsTheText”、“andSomeMoreText”、“noBracketsSometimes”、“someText”。输入的模式总是相同的,方括号中包含一些内容(或者可能不是),后面跟着一些空格(同样,可能不是),然后是我想要的实际文本。
我该怎么做?
谢谢
最佳答案
一种方法:
var actualTextYouWant = originalString.replace(/^\[[^\]]+\]\s*/, '');
这将返回 originalString
的副本,其中删除了初始 [...]
和空格。
关于Javascript正则表达式 - 获取[此处的内容]之后的所有文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12395967/