RegEX


SUBMITTED BY: Guest

DATE: Nov. 5, 2013, 9:43 p.m.

FORMAT: HTML

SIZE: 2.8 kB

HITS: 1167

  1. Stage 1
  2. Symbol Explanation
  3. ^ Start of string
  4. $ End of string
  5. . Any single character
  6. + One or more character
  7. \ Escape Special characters
  8. ? Zero or more characters
  9. Input exactly match with “abc”
  10. var A = /^abc$/;
  11. Input start with “abc”
  12. var B = /^abc/;
  13. Input end with “abc”
  14. var C = /abc$/;
  15. Input “abc” and one character allowed Eg. abcx
  16. var D = /^abc.$/;
  17. Input “abc” and more than one character allowed Eg. abcxy
  18. var E = /^abc.+$/;
  19. Input exactly match with “abc.def”, cause (.) escaped
  20. var F = /^abc\.def$/;
  21. Passes any characters followed or not by “abc” Eg. abcxyz12....
  22. var G = /^abc.+?$/
  23. Stage 2
  24. Char Group Explanation
  25. [abc] Should match any single of character
  26. [^abc] Should not match any single character
  27. [a-zA-Z0-9] Characters range lowercase a-z, uppercase A-Z and numbers
  28. [a-z-._] Match against character range lowercase a-z and ._- special chats
  29. (.*?) Capture everything enclosed with brackets
  30. (com|info) Input should be “com” or “info”
  31. {2} Exactly two characters
  32. {2,3} Minimum 2 characters and Maximum 3 characters
  33. {2,} More than 2 characters
  34. Put together all in one URL validation.
  35. var URL = /^(http|https|ftp):\/\/(www+\.)?[a-zA-Z0-9]+\.([a-zA-Z]{2,4})\/?/;
  36. URL.test(“http://9lessons.info”); // pass
  37. URL.test(“http://www.9lessons.info”); // pass
  38. URL.test(“https://9lessons.info/”); // pass
  39. URL.test(“http://9lessons.info/index.html”); // pass
  40. Stage 3
  41. Short Form Equivalent Explanation
  42. \d [0-9] Any numbers
  43. \D [^0-9] Any non-digits
  44. \w [a-zA-Z0-9_] Characters,numbers and underscore
  45. \W [^a-zA-Z0-9_] Except any characters, numbers and underscore
  46. \s - White space character
  47. \S - Non white space character
  48. var number = /^(\+\d{2,4})?\s?(\d{10})$/; // validating phone number
  49. number.test(1111111111); //pass
  50. number.test(+111111111111); //pass
  51. number.test(+11 1111111111); //pass
  52. number.test(11111111); //Fail

comments powered by Disqus