A regex finds matches more complex than a literal string for you. You can't replace a string with a matcher object, though! You could rewrite it with a description (the expression), but that's no help.

What you can often do is use captured content in the replacement string, using either \1 or $1 for the first captured text. So this would wrap whatever it found between commas with bars instead:

  • Find: ,([^,]*),
  • Replace: |\1|

The parentheses say what to capture. The square bracket thingy is normally a set of characters, but when you start with a ^, it becomes the inverted set, so here it's "zero or more of the set of every character but the comma".

It would rewrite (if run just once, not till more matches) like so:

  • ,abc, to |abc|
  • ,a,b,c, to |a|b,c
  • ,,, to ||,

Now, what happens if you replace the [^,] with just the "any character" expression dot . ? Try and see!

//