Javascript正则表达式 - 获取[此处的内容]之后的所有文本

标签 javascript regex string

我的程序中有如下字符串:

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/

相关文章:

php - 更改 youtube url 以在 php 中嵌入 url

c++ - XML 解析 : Checking for strings within string C++

java - java中如何删除空行和其余字符

javascript - 使用 JavaScript 重新加载 iframe

javascript - 将 javascript 客户端连接到 python websocket 服务器

javascript - 如何让discord.js 机器人重复在另一个 channel 中给它的消息?

java - 将正则表达式应用于 SAX 流

javascript - 如何在 Electron 应用程序的设置中添加 'System Language' 作为语言选项?

Python:匹配之间的连续行类似于 awk

c# - C++ 字符串与 C# 字符串,不同的运行时间。为什么?