code_junkie

Adding an AND clause to a regex

Nov 11th, 2011
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. [d]{1,5}
  2.  
  3. [d]{1,5}|[^0]{1}
  4.  
  5. [1-9]d{0,4}
  6.  
  7. ^0*[1-9]d{0,4}$
  8.  
  9. #!/bin/perl -w
  10.  
  11. while (<>)
  12. {
  13. chomp;
  14. print "OK: $_n" if m/^(?!0+$)d{1,6}$/;
  15. }
  16.  
  17. 0
  18. 00
  19. 000
  20. 0000
  21. 00000
  22. 000000
  23. 0000001
  24. 000001
  25. OK: 000001
  26. 101
  27. OK: 101
  28. 01
  29. OK: 01
  30. 00001
  31. OK: 00001
  32. 1000
  33. OK: 1000
  34. 101
  35. OK: 101
  36.  
  37. ^(?=regex1)(?=regex2)(?=regex3).*
  38.  
  39. ^(?=d{1,5}$)(?=.*?[1-9]).*
  40.  
  41. var str = user_string;
  42. if ('0' != str && str.matches(/^d{1,5}$/) {
  43. // code for match
  44. }
  45.  
  46. var str = user_string;
  47. if (!str.matches(/^0+$/) && str.matches(/^d{1,5}$/) {
  48. // code for match
  49. }
  50.  
  51. ^([1-9][0-9]{0,4}|[0-9]{,1}[1-9][0-9]{,3}|[0-9]{,2}[1-9][0-9]{,2}|[0-9]{,3}[1-9][0-9]|[0-9]{,4}[1-9])$
Add Comment
Please, Sign In to add comment