gsub(/^/, "\t" * num)
What character is being substituted?
No character is being substituted, it is just inserting num
tabs at the beginning so you could say that it is substituting the zero width "beginning of line" marker. Whoever wrote that would have been better off with something more like this:
tabbed = "\t" * num + original
A regular expression really isn't the right tool for simple string concatenation.
Clarification: If you're expecting your string to contain multiple lines then using:
gsub(/^/, "\t" * num)
to prefix all the lines with tabs is a reasonably thing to do and less noisy than splitting, prefixing, and re-joining. If you're only expecting to deal with a single line in your string then simple string concatenation would be the better choice.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With