Skip to content

Instantly share code, notes, and snippets.

@lmarburger
Created May 30, 2009 13:54
Show Gist options
  • Save lmarburger/120505 to your computer and use it in GitHub Desktop.
Save lmarburger/120505 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
html = %{This is a test
This is only a test
<pre>This is
some text
in a PRE.</pre>
omg<pre></pre>
<pre></pre>stuff<pre></pre>
More text.
<pre>This is another</pre>}
regex = %r{<pre>[\s\S]*?</pre>|[^\r\n]+}
p html.scan(regex)
# => ["This is a test", "This is only a test", "<pre>This is\n\nsome text\nin a PRE.</pre>", "omg<pre></pre>", "<pre></pre>", "stuff<pre></pre>", "More text.", "<pre>This is another</pre>"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment