text_utils.py 777 B

123456789101112131415161718192021222324252627282930313233
  1. # -*- coding:utf-8 -*-
  2. import re, random
  3. def IsChineseCharInside(sentence):
  4. for uchar in sentence:
  5. if u'\u4e00' <= uchar <= u'\u9fa5':
  6. return True
  7. return False
  8. def isMatchRegExp(param, rule):
  9. if param is None or param == "":
  10. return True
  11. isRegular = False
  12. try:
  13. for word in param:
  14. matchObj = re.search(word, rule, re.M | re.I | re.S)
  15. if matchObj:
  16. isRegular = True
  17. else:
  18. return False
  19. return isRegular
  20. except Exception as err:
  21. return False
  22. def getRamdomNumber(size):
  23. str = ""
  24. for i in range(size):
  25. ch = chr(random.randrange(ord('0'), ord('9') + 1))
  26. str += ch
  27. return str