user3589620
user3589620

Reputation:

One comma in space

Find, for example in

yyyy , yyyy

yyyy,yyyy

yyyy, yyyy

yyyy ,yyyy

the pattern between yyyy and yyyy.

I've tried:

(\s*,{1}\s*)

but this will also match

yyyy,,yyyy.

Demo

What is missing?

Upvotes: 3

Views: 52

Answers (1)

Mariano
Mariano

Reputation: 6511

Using lookarounds:

(?<![,\s])\s*,\s*(?![,\s])
  • (?<![,\s]) is a negative lookbehind (?<!pattern). In this case, "not preceded by a comma or a whitespace"
  • (?![,\s]) is a negative lookahead (?!pattern). In this case, "not followed by a comma or a whitespace"

Upvotes: 1

Related Questions