Create and use a JavaScript Regular objectDeclare a JavaScript Regular Expression
VaR recat = new Regexp ("cat ");
You can also
VaR recat =/CAT/; // Perl style (recommended)
Learn the most common test exec match search replace split six methods1) test checks whether the specified string exists
VaR DATA = "123123 "; VaR recat =/123/GI; Alert (recat. Test (data); // true
// Check whether the character g exists. continue to the next step. I is case insensitive. |
2) exec returns the query value
VaR DATA = "123123,213,123, 312, 3, Cat, Cat, dsfsdfs ,"; VaR recat =/CAT/I; Alert(recat.exe C (data); // cat |
3) match to get the query Array
VaR DATA = "123123,213,123, 312, 3, Cat, Cat, dsfsdfs ,"; VaR recat =/CAT/GI; VaR arrmactches = data. Match (recat)For (VAR I = 0; I <arrmactches. length; I ++ ){ Alert (arrmactches [I]); // Cat } |
4) The returned search location is similar to indexof.
VaR DATA = "123123,213,123, 312, 3, Cat, Cat, dsfsdfs ,"; VaR recat =/CAT/GI; Alert (data. Search (recat); // 23 |
5) replace replacement characters with regular expressions
VaR DATA = "123123,213,123, 312, 3, Cat, Cat, dsfsdfs ,"; VaR recat =/CAT/GI; Alert (data. Replace (recat, "libinqq ")); |
6) Split splits the array using regular expressions.
VaR DATA = "123123,213,123, 312, 3, Cat, Cat, dsfsdfs ,"; VaR recat = /\,/; VaR arrdata = data. Split (recat );For (VAR I = 0; I <arrdata. length; I ++ ){ Alert (arrdata [I]); } |
Learning simple class negative class range class combination class
// Simple class VaR DATA = "1 libinqq, 2 libinqq, 3 libinqq, 4 libinqq "; VaR recat =/[123] libinqq/GI; VaR arrdata = data. Match (recat );For (VAR I = 0; I <arrdata. length; I ++) { Alert (arrdata [I]); // 1 libinqq 2 libinqq 3 libinqq } // Negative VaR DATA = "alibinqq, 1 libinqq, 2 libinqq, 3 libinqq, 4 libinqq"; // \ u0062cf VaR recat =/[^ A123] libinqq/GI; VaR arrdata = data. Match (recat ); For (VAR I = 0; I <arrdata. length; I ++) { Alert (arrdata [I]); // 4 libinqq } // Range VaR DATA = "libinqq1, libinqq2, libinqq3, libinqq4, libinqq5"; // \ u0062cf VaR recat =/libinqq [2-3]/GI; VaR arrdata = data. Match (recat ); For (VAR I = 0; I <arrdata. length; I ++) { Alert (arrdata [I]); // libinqq2 libinqq3 } // Combination VaR DATA = "a, B, c, W, 1, 2, 3, 5"; // \ u0062cf VaR recat =/[a-q1-4 \ n]/GI; VaR arrdata = data. Match (recat ); For (VAR I = 0; I <arrdata. length; I ++) { Alert (arrdata [I]); // a B C 1 2 3 } |
Cited by: http://blog.myspace.cn/e/405771220.htm