In this example, the sub method of the String class has been used; this takes a regular expression as its first argument (here /(^s*)#(.*)/) and a replacement string as the second argument (here '1//2') . The replacement string may contain numbered place-holders such as 1 and 2 to match any groups in the regular expression - here there are two groups between round brackets: (^s*) and (.*). The sub method returns a new string in which the matches made by the regular expression are substituted into the replacement string, while any un-matched elements (here the # character, are omitted).