Pavitran
Pavitran

Reputation: 47

Regex starts with word but exclude if matches word exactly

I want to take strings that start with syslog but but not syslog exactly

e.g:

So far, I have this to exclude syslog exactly:

(?!^syslog$)(^.*$)

Upvotes: 1

Views: 232

Answers (2)

Ryszard Czech
Ryszard Czech

Reputation: 18611

Use

^syslog.+

See proof.

EXPLANATION

--------------------------------------------------------------------------------
  ^                        the beginning of the string
--------------------------------------------------------------------------------
  syslog                   'syslog'
--------------------------------------------------------------------------------
  .+                       any character except \n (1 or more times
                           (matching the most amount possible))

Upvotes: 1

The fourth bird
The fourth bird

Reputation: 163207

You can match a non whitespace char \S after matching syslog, and then match the rest of the line without using a lookahead.

^syslog\S.*$

Regex demo

Upvotes: 1

Related Questions