特定字符串后的javascript多行匹配

特定字符串后的javascript多行匹配,javascript,regex,match,Javascript,Regex,Match,在本文中: my-Word: Value-1 othertext my-Word: Value-2 othertext my-Word: Value-3 ... 我需要匹配包含以下内容的所有字符串:([A-Za-z0-9-]+) 并且只在字符串之后:myword:,但不包括:myword: > var s = "my-Word: Value-1\nothertext\nmy-Word: Value-2\nothertext\nmy-Word: Value-3" undefined >

在本文中:

my-Word: Value-1
othertext
my-Word: Value-2
othertext
my-Word: Value-3
...
我需要匹配包含以下内容的所有字符串:
([A-Za-z0-9-]+)

并且只在字符串之后:
myword:
,但不包括:
myword:

> var s = "my-Word: Value-1\nothertext\nmy-Word: Value-2\nothertext\nmy-Word: Value-3"
undefined
> var re = /my-Word:\s*([A-Za-z0-9-]+)/gm;
undefined
> var m;
undefined
> while ((m = re.exec(s)) != null) {
... console.log(m[1]);
... }
Value-1
Value-2
Value-3
所以我只需要匹配:
Value-1
Value-2
Value-3
,等等


我该怎么做?

使用捕获组捕获出现在“我的单词:

> var s = "my-Word: Value-1\nothertext\nmy-Word: Value-2\nothertext\nmy-Word: Value-3"
undefined
> var re = /my-Word:\s*([A-Za-z0-9-]+)/gm;
undefined
> var m;
undefined
> while ((m = re.exec(s)) != null) {
... console.log(m[1]);
... }
Value-1
Value-2
Value-3

您可以使用正向查找:

(?<=my-Word:\s*)([A-Za-z0-9-]+)

(?您必须使用lookback正则表达式,例如:

.(?<=my-Word: [A-Za-z0-9-])[A-Za-z0-9-]+

组合两个正则表达式,
my Word:\s*([A-Za-z0-9-]+)
。从组索引1中获取值。@AvinashRaj您可以发布一个示例吗?我无法使其工作。@user3542686:您可以显示您正在尝试的代码未捕获的语法错误:无效正则表达式:/(?@Mohamadshiralizadeh您的正则表达式是一个lookback。@Mohamadshiralizadeh我的意思是它不是一个lookahead:)未捕获的语法错误:无效的正则表达式:/。(?