帮助纠正正则表达式 [英] Help correcting regular expression

查看:99
本文介绍了帮助纠正正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下正则表达式,我想获取LocationMappingNew和MobileClassLibraries.BL.Mobile在评论中所处的值。我写的模式是返回一个空值的组。


//" __ type":"LocationMappingNew:# MobileClassLibraries.BL.Mobile"


string pattern = " \" __ type \":\"([A-Za-z] *):# ([A-Za-z] *)\", ;


匹配 match = 正则表达式 .Match(objString, pattern, RegexOptions .IgnoreCase);

解决方案

您的模式有2个问题:
1。第二个[A-Za-z]不允许有时间段。您可以将其更改为:[A-Za-z。]
2。看起来您的模式末尾有逗号,因此您的输入将不匹配。

请尝试:"\" __ type \":\"([A -Za-Z] *):#([A-ZA-Z] *)\""结果

I have the following regular expression where I want to get the value where LocationMappingNew and MobileClassLibraries.BL.Mobile sit in the comment.  The pattern I wrote is returning 1 group with an empty value.

//"__type":"LocationMappingNew:#MobileClassLibraries.BL.Mobile"

string pattern = "\"__type\":\"([A-Za-z]*):#([A-Za-z]*)\",";

Match match = Regex.Match(objString,pattern,RegexOptions.IgnoreCase);

解决方案

2 problems with your pattern:
1. The 2nd [A-Za-z] doesn't allow for periods. You can change it to: [A-Za-z.]
2. It looks like you have a trailing comma at the end of your pattern, therefore your input won't match.

Try: "\"__type\":\"([A-Za-z]*):#([A-Za-z.]*)\""


这篇关于帮助纠正正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆