Home > Software engineering >  Match numbers of commas in a string not surrounded by numbers
Match numbers of commas in a string not surrounded by numbers

Time:12-29

Suppose I have the following string:

abc,400,00,foo,bar,34,000,,hello,bye

What would the proper regex be to match the number of commas that have a character both on the left and right side though both characters can't be numeric, and non can be other commas.

In the example string, the commas I placed inside the parentheses would be counted, the rest not.

abc(,)400,00(,)foo(,)bar(,)34,000,,hello(,)by

CodePudding user response:

enter image description here

You can user OR in your regex with two possible cases

CodePudding user response:

This should also work -

(?<=[^\d,]),

  • Related