如何寫一個正則表達式中輸入必須在Java腳本是這種特定的形式cn=<name>,ou=<name>,o=<bic8>,o=swift
的文本匹配定期對CN = <name>,OU = <name>,O = <bic8>,表達O =快捷
1
A
回答
3
function getMatch(str) {
var m = /^cn=(.*?),ou=(.*?),o=(.*?),o=swift$/.exec(str);
return (m) ? {cn:m[1], ou:m[2], o:m[3]} : null;
}
如果給定的字符串不匹配,則返回null,否則返回值爲「cn」,「ou」和「o」的對象。
var x = getMatch("cn=foo,ou=bar,o=zip,o=swift");
alert(x.cn); // => "foo"
alert(x.ou); // => "bar"
alert(x.o); // => "zip"
0
var regexp = /^[a-z]{1,2}[=]{1}[a-z0-9]+/;
+0
這將只匹配第一次出現的令牌。 – 2011-02-23 09:21:38
+0
您顯然從未受過[x509](http://tools.ietf.org/html/rfc1422)或[ldap](http://en.wikipedia.org/wiki/Lightweight_Directory_Access_Protocol#Directory_structure)的限制。 – sarnold 2011-02-23 09:24:31
相關問題
- 1. <o:p> </o:p>< o : p >&nbsp;</o : p >顯示錯誤
- 2. PHP - <=快捷
- 3. Java語法問題:<O> O接受(ObjectVisitorEx <O>訪客)
- 4. 解開AST <O(exp(n))?
- 5. 指定要<code>-o</code>爲browserify
- 6. PHP表達<<< EOB
- 7. <= vs <當證明大O符號時
- 8. 瞭解Makefile與.c = .o和$ <
- 9. -h <name>與-o <outputfile>之間的差異cc(C++)
- 10. 隊列<T> O(1)時間
- 11. IQueriable <T>對於比O(n)性能好的對象嗎?
- 12. 字符數組初始化:</p> <pre><code>char s[]={'I',' ','a','m',' ','a',' ','g','o','o','d',' ','g','u','y','\O'}; char s[]={'I',' ','a','m',' ','a',' ','g','o','o','d',' ','g','u','y',}; </code></pre> <p>是否總是需要在一端與NUL初始化字符數組:在端
- 13. 轉換表達<Func鍵<TEntity,TKEY的>,以表達<Func鍵<TEntity,對象>>
- 14. 改變的表達<func<>>
- 15. 表達式<Func <TModel,string >>到表達式<動作<TModel>>「Getter」到「Setter」
- 16. SPARQL如何接收不空?s在:select?s?p?o WHERE {<http://subject.url>?p?o}
- 17. Android Studio的鍵盤快捷鍵:ctrl + o
- 18. 表達式<Action<T>> methodCall
- 19. C++ - 錯誤:前預期主表達式 '<<' 令牌
- 20. 敏捷 - 期待等於<0.9602>,得到<0.9602>
- 21. 轉換表達<Func鍵<TInterface,布爾>>表達式<Func鍵<TImplementation,布爾>>
- 22. 表達<Func鍵<in T, bool>>或表達<Func鍵<TBase,bool>>表達式<Func<T,bool>>轉換器
- 23. 從表達式<Func <TypeIn,TypeOut1 >>轉換爲表達式<Func <TypeIn,TypeOut2 >>
- 24. 如何表達<Func鍵<T1, bool>>轉換爲表達<Func鍵<T2, bool>>
- 25. 將表達式<Func <XClass,object >>轉換爲表達式<Func <YClass,object >>
- 26. 將表達式<Func<T, U>>轉換爲表達式<Func <object,object >>
- 27. 轉換表達<Func鍵<T1,bool>>表達式<Func鍵<T2,bool>動態
- 28. 如何將表達式<Func <T, bool>>轉換爲表達式<Func <Type, bool>>?
- 29. 正則表達式:確定除了<tr>,,</td>或</tr>
- 30. 特定字符串格式正則表達式<><><>
活動目錄專有名稱? – Kobi 2011-02-23 09:14:48