March 2018
Beginner to intermediate
416 pages
9h 24m
English
gsub stands for global substitution (replace everywhere). It replaces every occurrence of a regular expression (original string) with the replacement string in the given string. The third argument is optional. If it is not specified, then $0 is used.
The gsub() function returns the number of substitutions made. The special character & works the same way as it worked in the sub() function earlier. It is similar to the g option used in sed, for converting all the occurrences apart from the first. So, if a pattern occurs more than once per line or string, the substitution will be performed for each pattern. The following example illustrates how the gsub() function works.
In this example, we have ...
Read now
Unlock full access