Now, we will move on to methods which replace all matching occurrences of a regular expression with a new expression. Again, Scala has two inbuilt functions which do exactly that and we will discuss each one below.
replaceAll
replaceAll is called on the string that needs to be modified either directly or using a string variable.
The syntax is identical to replaceFirst where SearchExpression is the expression you want to replace and ReplaceExpression is the expression you want to replace the previous expression with.
Let’s build upon the example for replaceFirst, but this time we want to replace all the 0’s and 1’s with X’s.