首页 > 代码库 > c#正则不识别正括号[

c#正则不识别正括号[

技术分享

如图,需要正则匹配14117.56这个数据

 

即在字符串(以下都为字符串)

var gridJSON = ‘[{"value":["10440312"],"key":1},{"value":["13278875"],"key":2},{"value":["78.62"],"key":3},{"value":["16249"],"key":4},{"value":["0.16"],"key":5},
{"value":["1.35"],"key":6},{"value":["0.87"],"key":7},{"value":["14117.56"],"key":8},{"value":["10440312"],"key":12}]‘;

中匹配14117.56这个字符串

 

正则的时候这么写

var priceRegex = new Regex("0.87\"],\"key\":7},{\"value\":[\"(.*)\"],\"key\":8}");

找不到匹配项,要将正则表达式改为

var priceRegex = new Regex("0.87\"],\"key\":7},{\"value\":\\[\"(.*)\"],\"key\":8}");

才可以匹配到

表达正括号  [   应该写作  \\[

 

c#正则不识别正括号[