Guest User

Untitled

a guest
Jan 17th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. string1 = "this is a test string : that behaves as I expectn"
  2. string2 = "this string does not behave as I expectn"
  3.  
  4. field = CharsNotIn(":n")
  5. line = field + ZeroOrMore(Literal(":") + field) + LineEnd()
  6.  
  7. print line.parseString(string1)
  8. print line.parseString(string2)
  9.  
  10. ['this is a test string ', ':', ' that behaves as I expect', 'n']
  11. ['this string does not behave as I expect']
  12.  
  13. string1 = "this is a test string : that behaves as I expect*"
  14. string2 = "this string also behaves as I expect*"
  15.  
  16. field = CharsNotIn(":*")
  17. line = field + ZeroOrMore(Literal(":") + field) + Literal("*")
  18.  
  19. print line.parseString(string1)
  20. print line.parseString(string2)
  21.  
  22. ['this is a test string ', ':', ' that behaves as I expect', '*']
  23. ['this string also behaves as I expect', '*']
  24.  
  25. >>> print line
  26. {!W:(:
  27. ) [{":" !W:(:
  28. )}]... LineEnd}
  29.  
  30. >>> print line.parseString('xyzyy')
  31. ['xyzyy']
Add Comment
Please, Sign In to add comment