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表达式:

https://regex101.com

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

here

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值