tregex.nim 573 B

1234567891011121314151617181920212223242526272829
  1. discard """
  2. output: "key: keyAYes!"
  3. """
  4. # Test the new regular expression module
  5. # which is based on the PCRE library
  6. when defined(powerpc64):
  7. # cheat as our powerpc test machine has no PCRE installed:
  8. echo "key: keyAYes!"
  9. else:
  10. import
  11. re
  12. if "keyA = valueA" =~ re"\s*(\w+)\s*\=\s*(\w+)":
  13. write(stdout, "key: ", matches[0])
  14. elif "# comment!" =~ re.re"\s*(\#.*)":
  15. # test re.re"" syntax
  16. echo("comment: ", matches[0])
  17. else:
  18. echo("Bug!")
  19. if "Username".match(re"[A-Za-z]+"):
  20. echo("Yes!")
  21. else:
  22. echo("Bug!")
  23. #OUT key: keyAYes!