0

Is there a way to invert a RegEx selection?

I have the following string example:

Hello World

<h1>{{{title}}}</h1>

No HTML

<p>{{description}}</p>

{{#each projects}}
    <h2>{{#name}}</h2>
    <bockquote><p>{{#quote}}</p></bockquote>
    <p>{{#description}}</p>
    <pre><code class="lang-javascript">{{{#code}}}</code></pre>
{{/each}}

I want to select the text which is NOT surrounded by HTML-Tags OR Handlebar-Tags.

My approach was to select the HTML/Handlebar-Tags and then invert the selection. The RegEx for this looks like:

/<(.*)>|{{.*}}/

But I just cant find a way to invert this. Is there another way?

General Grievance
  • 4,555
  • 31
  • 31
  • 45
misantronic
  • 1,132
  • 2
  • 10
  • 23
  • 2
    [You can't parse (X)HTML with regex.](http://stackoverflow.com/a/1732454/1529630) – Oriol Nov 05 '14 at 01:05
  • What @Oriol said. Write a simple token parser and run through this data instead of trying to use regexp for this purpose. – Mike 'Pomax' Kamermans Nov 05 '14 at 01:07
  • Even your original regex is incorrect, since it will eat up from `<` to the last `>` in a line, and go outside the boundary of a tag. The other one `{{.*}}` only works if there is only 1 instance per line. – nhahtdh Nov 05 '14 at 02:22

1 Answers1

0

the match is in group 1

(?:<.*?>|\{\{.*?}})|([^{}<>]*)