Nick
Nick

Reputation: 35

Regex: How to exclude a string if it contains a specific character?

I want to match any string that doesn't contain "S", if it contains it should be excluded.

Sample:

Sally Desk 
Camp Silly
Not Bad

Expected Result:

Desk  
Camp  
Not  
Bad

Upvotes: 1

Views: 3280

Answers (1)

vks
vks

Reputation: 67968

I want to match any string that doesn't contain "S"

You can simply use (?!\S*S)\b\S+\b.This uses lookahead to check if string doesnt contain S

See demo.

https://regex101.com/r/uF4oY4/1

Upvotes: 2

Related Questions