帮助纠正正则表达式 [英] Help correcting regular expression
问题描述
我有以下正则表达式,我想获取LocationMappingNew和MobileClassLibraries.BL.Mobile在评论中所处的值。我写的模式是返回一个空值的组。 //" __ type":"LocationMappingNew:# MobileClassLibraries.BL.Mobile"
匹配 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"
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屋!