jquery REGEX for longstring with azAZ-09-specialchars and |

时间:2012-04-18 11:46:16

标签: javascript jquery regex

你好,有人可以在jquery正则表达式中帮助我吗? 从昨晚开始,我就在这里堆积,最后我决定寻求帮助:)

任何这里的我的正则表达式abd字符串是在exg变量..然后我想拆分每个字符串

匹配[0] = 'eNortjI0sLBScgQDz3yTfK98XCdH59RKc4M8&安培; + SSXFzzXFz3UE9H9yzfYMfCYtPiDLes0NSAXCL3nIj0osJcIvNCjwxLv6z8YhPTXFxv8&安培; KSMNekjIrgqqzQvOJyy0zXNPMoZ4vS0PQS4 + S0&安培; IIgU7OssPIolygXJWtcMMMFXCch | eNortjI0sLRScgQDz3yTfK98XCfHXDBDjzx3X4&安培; cXCLXygKn4tzsNCNcJ + NMK + xEM6Ok&安培; OIq1 + DcXFxLw8AwjyhHb480lyxTg&安培; LkKv8sXw&安培; zpCSnJE + XYo&安培; EVH&安培; 3yKyAsMjEtKxSi4CIqlwigwL&安培; giinXDC3wCiXKBcla1wwpPEmEA == |';

匹配[1] = 'eNortjI0NLJScgQDz3yTfK98XCdH9yCPZJ&安培; CiCpD36xcMMuSsLwox6qAwMqkUAPTlChHI8ugvDQL9zzjbBMfT8u8RIOgMgvnHJ9SpzynvFDfQAugijBLv6CgXDBT&安培; 0LzKMdI06BIf9OyKGd&安培; U58kN19fV8colygXJWtcMNaqJP8 = |';

var regex = /[a-zA-Z]+[0-9]+[/-=&_]+|/g;

var exg = 'eNortjI0sLBScgQDz3yTfK98XCdH59RKc4M8&+SSXFzzXFz3UE9H9yzfYMfCYtPiDLes0NSAXCL3nIj0osJcIvNCjwxLv6z8YhPTXFxv8&KSMNekjIrgqqzQvOJyy0zXNPMoZ4vS0PQS4+S0&IIgU7OssPIolygXJWtcMMMFXCch|eNortjI0sLRScgQDz3yTfK98XCfHXDBDjzx3X4&cXCLXygKn4tzsNCNcJ+NMk+xEM6Ok&OIq1+DcXFxLw8AwjyhHb480lyxTg&LkKv8sXw&zpCSnJE+XYo&EVH&3yK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H&4z8yCin0szUgNwo54zkkBDTJB&TrIBA06S8XFxvr7SKyuDsKOeIZOPcsFA&&4woZ49UU&ekIKMq&7DURCOLimRjX9eKSmdDxxwXZ4&wjDT&lLDsJI&iqpB01yhcJ4v0KJcoFyVrXDA8ZVwnTQ==|eNortjI0MrBScgQDz3yTfK98XCdHLy&LSLfMyOxcIvfIioJit9Lc9NC04NK8NEvncHe&9Byv5MRwy8pC79ywgLT0SJ+qjORCC5PK0oh8i8yU0gpPR9PK7BJXn9SCxDznsEQXb7e8LLMCp+L8tMTyKJcoF7XUioLMotTi+Mw8WwMla1ww8SosXw==|eNortjI0NLRScgQDz3yTfK98XCdHr0pcJ+PAdP9sc+NcIvcyY4PEoNywyuyKzOQsC8twDx9Hg7TUkHyv7BDjMtPg3LwcjyinqlwiNxcXXCeXKFwn7wggEWmck59YHJhZ5Z4ZmF4R5eSfaFnkWuzpVFRglpxcXB7lEuWiZA1cMO+XJv4=|eNortjI0MLdScgQDz3yTfK98XCdHr7LgEpekEmO&xIBgo5CMoOSSKu&QDKPK5OziojS&&Bwvk&BK4yqLCFOjTNNcXC9Tz8C0jLzSkuCMYI88v8KIwORQi&TMQLM8i&B8Sy9Pl7QqXwt&gxQvrzLHKJcoFyVrXDCNviXB|eNortjI0NLRScgQDz3yTfK98XCdHn4pCp5yQxNIkM8MQ97SI0PLkoIqy9DJvZ3PXgPDwgKSIKKfwPKfi&CqvtAqTTNf0YMdwS8cM&yjH7Mr0omTTsLQqg&RcXLOK9Oz00LDgwijHCOeqyuC8KFwnf2fvSMcolygXJWtcMD&GXCfp|eNortjI0NLBScgQDz3yTfK98XCdHF6&gcEdTr5SiNO8KY1wnk1KLIE&&yowox+JcMB&XlGyzQH8&gwKvyIjyEMuyNI+ktMSQ7DDzdAsTA&fyKMckl&KS9HDDgNRKL0+jkCintLCStFwin+LcRC+PXFxcJ7+qwCiXKBcla1wwqjUmMg=='

   if(regex.test(exg)) {
      var matches = exg.match(regex);
      for(var match in matches) {
            alert(matches[match]);
      } 
       } else {
         alert("No matches found!");
       }`

但我的正则表达式不会起作用,有人可以给我一个正确的正则表达式吗? :)请帮忙..

3 个答案:

答案 0 :(得分:1)

Elias的答案可能是最简单的方法,但如果你坚持使用正则表达式,那么这个怎么样:

var regex = /[a-zA-Z0-9\/-=&_+]+\|{0,1}/g

解释你的正则表达式以及为什么它不起作用:

[a-zA-Z]+  // Match one or more a-z upper or lower case
[0-9]+     // *THEN* match one or more 0-9
[/-=&_]+   // *THEN* match one or more of these characters
|          // *THEN* match a pipe

这里的问题是搜索字符串中的字母,数字和符号混合在一起。因此,它们都需要放在方括号内,以便您在任何顺序中将它们中的一个或多个匹配在一起。你把它们按照特定的顺序排列,首先是字母,然后是数字,然后是符号。

末尾的{0,1}匹配零个或一个管道,因此将捕获最后一个没有管道的匹配。

Incidentely没有JQuery正则表达式这样的东西。正则表达式函数是javascript。

答案 1 :(得分:0)

嗯...如何使用split,如marches = yourString.split('|');

这将返回一个字符串数组,但不会包含管道字符,但如果需要,只需将它们连接到子字符串。

答案 2 :(得分:0)

你之前错过了斜线,所以这可能是你想要的吗?

var regex = /[a-zA-Z0-9\/-=&_]+\|/g;