【发布时间】:2016-01-09 20:41:50
【问题描述】:
我试图匹配(但不包括!)JavaScript 中最后一次出现的字符串之后的所有内容。
例如,搜索是:
[quote="user1"]this is the first quote[/quote]\n[quote="user2"]this is the 2nd quote and some url https://www.google.com/[/quote]\nThis is all the text I\'m wirting about myself.\n\nLook at me ma. Javascript.
编辑:我希望匹配最后一个引用块之后的所有内容。所以我试图在最后一次出现 "quote]" 之后匹配所有内容? Idk 如果这是最好的解决方案,但它是我一直在尝试的。
说实话,我很讨厌这个正则表达式的东西。这是我一直在尝试的结果。
regex = /(quote\].+)(.*)/ig; // Returns null
regex = /.+((quote\]).+)$/ig // Returns null
regex = /( .* (quote\]) .*)$/ig // Returns null
我制作了一个 JSfiddle 供任何人在这里玩:
【问题讨论】:
-
我不明白你想匹配什么。 what 字符串在您的字符串中的最后一次出现?
-
对不起,我正在尝试匹配最后一个引号之后的所有内容...
-
那为什么要使用正则表达式呢?使用带有 lastIndexOf 的子字符串。
标签: javascript regex