From: Sean O'Halpin Date: 2005-10-19T03:30:33+09:00 Subject: Re: Regexp problem for template language On 10/18/05, Tobias Luetke wrote: > I omitted the {{ }} search from the regexp for this example, the > second part was only for trying to get all the text in between {% tags > %}. require 'test/unit' TokenizationRegexp = /(\{%.*?%\})|(\{\{.*?\}\})/ # with {{}} tags class ParsingTest < Test::Unit::TestCase def test_tokenization text = "Hello im liquid this: {% is a tag %} curly brackets like this { may appear in the text } please parse {{me}}" assert_equal ["Hello im liquid this: ", "{% is a tag %}", " curly brackets like this { may appear in the text } please parse ", "{{me}}"], text.split(TokenizationRegexp) # Note: using split end def test_tokenization_without_curly text = "Hello im liquid this: {% is a tag %}" assert_equal [ "Hello im liquid this: ", "{% is a tag %}"], text.split(TokenizationRegexp) # Note: using split end end -- OUTPUT -- Loaded suite liquid-regex Started .. Finished in 0.0 seconds. 2 tests, 2 assertions, 0 failures, 0 errors Regards, Sean