regex to find instance of a word or phrase -- except if that word or phrase is in braces -


First of all, a disclaimer. I know something about Reggae but I am not an expert. They look like something that I really need twice a year, so they do not stay "up" of my brain.

Status: I want to write a regex to match a certain word, let's call it "ostrich". easy. Except ostriches can sometimes appear inside a curly brace. If this is inside a curly brace then this is not a match. The trick here is that there may be spaces within curly braces. Apart from this, the text is usually inside the paragraph. I

This should match: I have an ostrich.

It should not match: went to my emu {ostrich race name}. <

It should be a match: went to my ostrich (ostriches race name).

This should not be a match: went to my emu {race ostrich place} went to my emu {race place ostrich}.

It seems that it is possible with a regex, but I'm not sure to see it.

I will provide an alternative solution to do that, which is slightly stronger (not using regex Make a claim)).

First of all, remove all code, such as {[^}] +} (change it to change to an empty string).

Now you can search for ostrich (using regex or simple string matching, according to your requirements).


Comments

Popular posts from this blog

c++ - QtQuick: QQmlApplicationEngine failed to load component qrc:/main.qml:23 Invalid attached object assignment -

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net - getting a value of selected radiobutton in LoadViewState -