Question

I am trying to write a pattern match to only match when a string is not followed by both following patterns. Right now I have a pattern that I've tried to manipulate but I can't seem to get it to match correctly.

Current pattern:

/(address|alias|parents|members|notes|host|name)(?!(\t{5}|\S+))/

I am trying to match when a string is not spaced correctly but not if it is part of a larger word.

For example I want it to match,

host \t{4} something

but not,

hostgroup \t{5} something

In the above example it will match hostgroup and end up separating it into 2 separate words "host" and "group"

Match:

notes \t{4} something

but not,

notes_url \t{5} something

Using my pattern it ends up turning into:

notes \t{5} _url

Hopefully that makes a bit more sense.

Was it helpful?

Solution

I'm not at all clear what you want, but word boundaries will probably do what you ask.

Does this work for you?

/\b(address|alias|parents|members|notes|host|name)\b(?!\t{5})/

Update

Having understood your problem better, does this do what you want?

/\b(address|alias|parents|members|notes|host|name)\b(?!\t{5}(?!\t))/
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top