为什么这个正则表达式不起作用?

时间:2014-12-16 05:36:40

标签: c# regex

我不知道为什么下面的表达不起作用。我期待单个正则表达式模式在C#和javascript代码中都有效。

模式

^格式=唯一标识符:CanvasHeight:CanvasWidth []逗号分隔[[] Lx的:LY:的Mx:我的[]]#值= [0-9A-ZA-Z] +:[0-9] + :[0-9] + [] [ - ] {0,1} [0-9] +:[ - ] {0,1} [0-9] +:[ - ] {0,1 } [0-9] +:[ - ] {0,1} [0-9] +([ - ] {0,1} [0-9] +:[ - ] {0,1} [O- 9] +:[ - ] {0,1} [0-9] +:[ - ] {0,1} [0-9] +)* $

格式=唯一标识符:CanvasHeight:CanvasWidth *逗号分隔[Lx的:LY:的Mx:我]#值= 1393:80:300 * 29:18:29:17,29:19:29:18,28:23: 29:19,26:27:28:23,26:32:26:27,25:35:26:32,24:39:25:35,23:44:24:39,22:48:23: 44,22:50:22:48,22:53:22:50,21:55:22:53,20:57:21:55,20:58:20:57,20:59:20:58, 20:60:20:59,20:61:20:60,18:62:20:61,18:64:18:62,18:65:18:64,18:66:18:65,18: 31:18:30,19:27:18:31,22:26:19:27,25:23:22:26,31:21:25:23,40:18:31:21,47:17: 40:18,55:15:47:17,62:15:55:15,67:13:62:15,70:13:67:13,71:13:70:13,72:13:71: 13,73:13:72:13,74:13:73:13,75:13:74:13,75:15:75:13,73:18:75:15,72:19:73:18, 71:20:72:19,69:22:71:20,68:23:69:22,64:27:68:23,63:28:64:27,61:29:63:28,59: 31:61:29,57:32:59:31,55:33:57:32,54:33:55:33,52:34:54:33,52:35:52:34,51:35: 52:35,50:36:51:35,47:37:50:36,46:38:47:37,45:38:46:38,45:40:45:38,45:41:45: 40,44:43:45:41,43:44:44:43,42:44:43:44104:37:104:36102:36:104:37,97:38:102:36,88:40: 97:38,85:42:88:40,80:44:85:42,76:45:80:44,71:48:76:45,70:49:71:48,66:50:70: 49,66:51:66:50,65:52:66:51,65:54:65 :52,65:55:65:54,65:56:65:55,65:57:65:56,65:58:65:57,66:58:65:58,68:58:66:58 ,69:58:68:58,72:58:69:58,75:58:72:58,77:57:75:58,80:56:77:57,82:54:80:56,84 :52:82:54,85​​:51:84:52,85:50:85:51,85:49:85:50,86:50:85:49,86:53:86:50,86:54 :86:53,88:56:86:54,90:57:88:56,91:57:90:57,91:56:91:57,92:54:91:56,92:51:92 :54,92:50:92:51,92:49:92:50,93:49:92:49,93:47:93:49,96:46:93:47105:43:96:46109:43 105:43116:42:109:43118:40:116:42120:39:118:40121:39:120:39122:39:121:39122:40:122:39122:43:122:40122:45:122 :43122:47:122:45122:49:122:47122:50:122:49122:51:122:50122:52:122:51123:53:122:52124:53:123:53125:53:124:53128 :52:125:53128:51:128:52131:45:128:51133:41:131:45134:35:133:41134:31:134:35136:29:134:31136:27:136:29137:25 :136:27137:21:137:25137:20:137:21137:19:137:20137:20:137:19137:26:137:20137:28:137:26137:32:137:28138:37:137 :32139:40:138:37139:43:139:40140:45:139:43141:47:140:45142:47:141:47142:48:142:47142:49:142:48143:49:142:49144 :48:143:49145:47:144:48146:43: 145:47147:42:146:43148:40:147:42149:38:148:40149:35:149:38151:34:149:35152:32:151:34154:29:152:32154:28:154: 29154:27:154:28154:26:154:27154:25:154:26153:25:154:25152:28:153:25152:32:152:28152:36:152:32151:38:152:36151: 40:151:38151:41:151:40151:43:151:41150:44:151:43150:45:150:44150:46:150:45150:47:150:46150:48:150:47150:49: 150:48150:50:150:49150:51:150:50150:52:150:51150:53:150:52152:53:150:53155:52:152:53159:49:155:52163:47:159: 49165:47:163:47169:45:165:47171:45:169:45173:45:171:45174:45:173:45175:45:174:45177:46:175:45178:47:177:46180: 48:178:47182:48:180:48185:49:182:48187:49:185:49188:49:187:49190:48:188:49191:48:190:48192:47:191:48193:46: 192:47194:45:193:46194:44:194:45196:43:194:44196:42:196:43197:40:196:42198:39:197:40199:38:198:39200:38:199: 38201:37:200:38201:36:201:37,65:69:65:68,67:68:65:69,70:68:67:68,76:68:70:68,86:68: 76:68,98:68:86:68110:68:98:68133:68:110:68150:68:133:68166:68:150:68184:68:166:68195:67:184:6 8206:67:195:67210:67:206:67213:66:210:67238:51:238:50303:39:303:38

1 个答案:

答案 0 :(得分:-2)

该死的,我在Regex.IsMatch()中错放了模式和值。一切都好。

这是在C#和javascript中都有效的模式。

^Format=UniqueIdentifier:CanvasHeight:CanvasWidth\*CommaSeparated\[Lx:Ly:Mx:My\]#Values=[0-9a-zA-Z]+:[0-9]+:[0-9]+\*[-]{0,1}[0-9]+:[-]{0,1}[0-9]+:[-]{0,1}[0-9]+:[-]{0,1}[0-9]+(,[-]{0,1}[0-9]+:[-]{0,1}[0-9]+:[-]{0,1}[0-9]+:[-]{0,1}[0-9]+)*$