user19714507
user19714507

Reputation:

Create a regular expression pattern to match all lines that don't contain form

I want to create a regular expression to match all lines that don't contain "form."

For example, for the below

form.id
    </div>
form-group
      <label for="url">URL</label>
form.url
    </div>

I tried to use look ahead, but it doesn't work.

The patter I use is

^.*(?!form\.).*$

This actually matched all lines including those lines like form.id

Upvotes: 0

Views: 46

Answers (1)

Aras
Aras

Reputation: 70

In your pattern it can find form keyword on the initial ".*" part and find a not containing "form." substring in any other part of the line.

You should make the negative lookahead contain all the line to avoid such a match.

This should do your job since it looks at all line from the beginning to find longest sequence which does not match "form." then adds the rest of the line.

^(?!.*form\.).*$

Upvotes: 0

Related Questions