50字范文,内容丰富有趣,生活中的好帮手!
50字范文 > java 正则表达式匹配冒号_用于匹配与冒号连接的单词对的正则表达式

java 正则表达式匹配冒号_用于匹配与冒号连接的单词对的正则表达式

时间:2023-12-29 11:31:17

相关推荐

java 正则表达式匹配冒号_用于匹配与冒号连接的单词对的正则表达式

我目前正在我的nodejs应用程序中解决这个问题,发现这是,我猜,适合于冒号配对词:

([\w]+:)("(([^"])*)"|'(([^'])*)'|(([^\s])*))

它还匹配引用值。喜欢

a:"b" c:'d e' f:g

ES6中的编码示例:

const regex = /([\w]+:)("(([^"])*)"|'(([^'])*)'|(([^\s])*))/g;

const str = `category:"live casino" gsp:S1aik-UBnl aa:"b" c:'d e' f:g`;

let m;

while ((m = regex.exec(str)) !== null) {

// This is necessary to avoid infinite loops with zero-width matches

if (m.index === regex.lastIndex) {

regex.lastIndex++;

}

// The result can be accessed through the `m`-variable.

m.forEach((match, groupIndex) => {

console.log(`Found match, group ${groupIndex}: ${match}`);

});

}

PHP中的示例编码

$re = '/([\w]+:)("(([^"])*)"|\'(([^\'])*)\'|(([^\s])*))/';

$str = 'category:"live casino" gsp:S1aik-UBnl aa:"b" c:\'d e\' f:g';

preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);

// Print the entire match result

var_dump($matches);

可以使用此联机工具检查/测试regex表达式:

顺便说一句,如果没有删除,您可以浏览该示例编码。

here

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。