TheGeneral
TheGeneral

Reputation: 81523

Regex match any 2 character combinations only if contains at least 1 specified character

I'm trying to match any space and comma combination as long as it contains at least 1 comma

Test case

"aaa,bbb    ccc ,, ddd  ,,  ,, , eee," 

Results

"aaa,bbb  ccc,,ddd,, ,, ,eee,"

What i have

[\s,]+(?!,)

However this selects spaces without commas

Upvotes: 1

Views: 58

Answers (1)

Gurmanjot Singh
Gurmanjot Singh

Reputation: 10360

Try this regex:

[, ]*,[, ]*

Click for Demo

Explanation:

  • [, ]* - matches 0+ occurrences of either a space or a ,
  • , - matches single occurrence of a ,
  • [, ]* - matches 0+ occurrences of either a space or a ,

Upvotes: 4

Related Questions