shinemic

AHK匹配正整数

Jul 1st, 2020
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. testcases := [  "123"
  2.               , "123."
  3.               , "123.00"
  4.               , "-10.00"
  5.               , "abc10.-1",
  6.               , "<10.000001>"
  7.               , "abc"
  8.               , "1.000000000000001"
  9.               , "1.0000000000000001"]
  10.  
  11. funs := ["IntegerMatchMath", "IntegerMatchRegex", "IntegerMatchRegexSimple"]
  12.  
  13. For _, case In testcases {
  14.     For _, fun In funs {
  15.         OutputDebug % Format("[{}] | {} => {}", fun, case, %fun%(case))
  16.     }
  17.     OutputDebug `n
  18. }
  19.  
  20. IntegerMatchRegex(s) {
  21.     Return s ~= "(?<![-\.\d])+?\d+(\.(0*)(?!\d)|(?![\.\d]))" ? (s " -- 匹配") : (s " -- 不匹配")
  22. }
  23.  
  24. IntegerMatchRegexSimple(s) {
  25.     Return s ~= "^\+?\d+(\.0*)?$" ? (s " -- 匹配") : (s " -- 不匹配")
  26. }
  27.  
  28. IntegerMatchMath(s) {
  29.     Return Abs(s // 1) = s ? (s " -- 匹配") : (s " -- 不匹配")
  30. }
  31.  
  32. ; [IntegerMatchMath] | 123 => 123 -- 匹配
  33. ; [IntegerMatchRegex] | 123 => 123 -- 匹配
  34. ; [IntegerMatchRegexSimple] | 123 => 123 -- 匹配
  35.  
  36. ; [IntegerMatchMath] | 123. => 123. -- 匹配
  37. ; [IntegerMatchRegex] | 123. => 123. -- 匹配
  38. ; [IntegerMatchRegexSimple] | 123. => 123. -- 匹配
  39.  
  40. ; [IntegerMatchMath] | 123.00 => 123.00 -- 匹配
  41. ; [IntegerMatchRegex] | 123.00 => 123.00 -- 匹配
  42. ; [IntegerMatchRegexSimple] | 123.00 => 123.00 -- 匹配
  43.  
  44. ; [IntegerMatchMath] | -10.00 => -10.00 -- 不匹配
  45. ; [IntegerMatchRegex] | -10.00 => -10.00 -- 不匹配
  46. ; [IntegerMatchRegexSimple] | -10.00 => -10.00 -- 不匹配
  47.  
  48. ; [IntegerMatchMath] | abc10.-1 => abc10.-1 -- 不匹配
  49. ; [IntegerMatchRegex] | abc10.-1 => abc10.-1 -- 匹配
  50. ; [IntegerMatchRegexSimple] | abc10.-1 => abc10.-1 -- 不匹配
  51.  
  52. ; [IntegerMatchMath] | <10.000001> => <10.000001> -- 不匹配
  53. ; [IntegerMatchRegex] | <10.000001> => <10.000001> -- 不匹配
  54. ; [IntegerMatchRegexSimple] | <10.000001> => <10.000001> -- 不匹配
  55.  
  56. ; [IntegerMatchMath] | abc => abc -- 不匹配
  57. ; [IntegerMatchRegex] | abc => abc -- 不匹配
  58. ; [IntegerMatchRegexSimple] | abc => abc -- 不匹配
  59.  
  60. ; [IntegerMatchMath] | 1.000000000000001 => 1.000000000000001 -- 不匹配
  61. ; [IntegerMatchRegex] | 1.000000000000001 => 1.000000000000001 -- 不匹配
  62. ; [IntegerMatchRegexSimple] | 1.000000000000001 => 1.000000000000001 -- 不匹配
  63.  
  64. ; [IntegerMatchMath] | 1.0000000000000001 => 1.0000000000000001 -- 匹配
  65. ; [IntegerMatchRegex] | 1.0000000000000001 => 1.0000000000000001 -- 不匹配
  66. ; [IntegerMatchRegexSimple] | 1.0000000000000001 => 1.0000000000000001 -- 不匹配
Add Comment
Please, Sign In to add comment