

{"id":17927,"date":"2018-06-08T04:10:23","date_gmt":"2018-06-08T04:10:23","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=17927"},"modified":"2021-12-04T10:15:28","modified_gmt":"2021-12-04T04:45:28","slug":"scala-regex","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/scala-regex\/","title":{"rendered":"Scala Regex | Scala Regular Expressions &#8211; Replacing Matches"},"content":{"rendered":"<p>In our last tutorial, we studied <a href=\"https:\/\/data-flair.training\/blogs\/scala-trait-mixins\/\"><strong>Scala Trait<\/strong> <strong>Mixins<\/strong><\/a>.<strong>\u00a0<\/strong>Today, we are going to discuss Scala Regular Expressions or in general terms, we call it Scala Regex. In this Scala Regex cheat sheet, we will learn syntax and example of Scala Regular Expression, also how to Replace Matches and\u00a0Search for Groups of Scala Regex.<\/p>\n<p>So, let&#8217;s begin Scala Regular Expression (Regex).<\/p>\n<h3 class=\"western\">What is Scala Regex?<\/h3>\n<p>We now move on to regular expressions. Using certain strings, we can find patterns and lack of patterns in data.\u2019 To convert a string into a regular expression, use the .r method. We import the Regex class from the package scala.util.matching.Regex.<br \/>\n<strong><a href=\"https:\/\/data-flair.training\/blogs\/scala-closures\/\">Let&#8217;s Discuss Scala Closures with Examples\u00a0<\/a><\/strong><\/p>\n<pre class=\"EnlighterJSRAW\">scala&gt; val word=\"portmanteau\".r\r\nword: scala.util.matching.Regex = portmanteau\r\nscala&gt; val str=\" Scala is a portmanteau of scalable and language\"\r\nstr: String = Scala is a portmanteau of scalable and language\r\nscala&gt; word findFirstIn str\r\nres9: Option[String] = Some(portmanteau)<\/pre>\n<p>Here, Scala converts the String to a RichString and invokes r() for an instance of Regex. We define a word and a string to search in. Then, we call the method findFirstIn() to find the first match. For a string with multiple occurrences, we can use findAllIn() to find all occurrences.<\/p>\n<h3 class=\"western\">Scala Regular Expressions Example<\/h3>\n<p>Let\u2019s take another example of Scala Regex.<\/p>\n<pre class=\"EnlighterJSRAW\">scala&gt; import scala.util.matching.Regex\r\nimport scala.util.matching.Regex\r\nscala&gt; val word=new Regex(\"(i|I)ntern\")\r\nword: scala.util.matching.Regex = (i|I)ntern\r\nscala&gt; val str=\"An intern on the Internet\"\r\nstr: String = An intern on the Internet\r\nscala&gt; (word findAllIn str).mkString(\", \")\r\nres10: String = intern, Intern<\/pre>\n<p>Here, we use the Regex() constructor to create the pattern, the method findAllIn() to find all occurrences of the word, and a pipe(|) to allow any case of a certain letter.<\/p>\n<h3 class=\"western\">How to Replace Matches in Scala Regex?<\/h3>\n<p>To replace a first match, we use the method replaceFirstIn(). To replace all matches, we use replaceAllIn().<\/p>\n<pre class=\"EnlighterJSRAW\">scala&gt; val word=\"Python\".r\r\nword: scala.util.matching.Regex = Python\r\nscala&gt; val str=\"I'm doing Python\"\r\nstr: String = I'm doing Python\r\nscala&gt; word replaceFirstIn(str,\"Scala\")\r\nres11: String = I'm doing Scala<\/pre>\n<h3 class=\"western\">Searching for Groups of Scala Regular Expression<\/h3>\n<p>We can use parentheses to search for groups of regular expressions in Scala.<\/p>\n<pre class=\"EnlighterJSRAW\">scala&gt; val pattern=\"([0-9a-zA-Z-#() ]+): ([0-9a-zA-Z-#() ]+)\".r\r\npattern: scala.util.matching.Regex = ([0-9a-zA-Z-#() ]+): ([0-9a-zA-Z-#() ]+)\r\nscala&gt; val str=\r\n| \"\"\"background-color: #A03300;\r\n| background-image: url(img\/header100.png);\r\n| background-position: top center;\r\n| background-repeat: repeat-x;\r\n| background-size: 2160px 108px;\r\n| margin: 0;\r\n| height: 108px;\r\n| width: 100%;\"\"\".stripMargin\r\nstr: String =\r\nbackground-color: #A03300;\r\nbackground-image: url(img\/header100.png);\r\nbackground-position: top center;\r\nbackground-repeat: repeat-x;\r\nbackground-size: 2160px 108px;\r\nmargin: 0;\r\nheight: 108px;\r\nwidth: 100%;\r\nscala&gt; for(patternMatch&lt;-pattern.findAllMatchIn(str))\r\n| println(s\"key:${patternMatch.group(1)} value:${patternMatch.group(2)}\")\r\nkey:background-color value:#A03300\r\nkey:background-image value:url(img\r\nkey:background-position value:top center\r\nkey:background-repeat value:repeat-x\r\nkey:background-size value:2160px 108px\r\nkey:margin value:0\r\nkey:height value:108px\r\nkey:width value:100<\/pre>\n<p><strong><a href=\"https:\/\/data-flair.training\/blogs\/inheritance-in-java\/\">Let&#8217;s study Inheritance in Java Programming Language\u00a0<\/a><\/strong><\/p>\n<h3 class=\"western\">The syntax of Scala Regex<\/h3>\n<p>Where Java inherits many features from Perl, Scala inherits the syntax of Scala regular expressions from Java. Here\u2019s the list of metacharacter syntax:<\/p>\n<table width=\"623\" cellspacing=\"0\" cellpadding=\"7\">\n<colgroup>\n<col width=\"297\" \/>\n<col width=\"297\" \/> <\/colgroup>\n<tbody>\n<tr>\n<td width=\"297\">\n<p align=\"center\"><b>Subexpression<\/b><\/p>\n<\/td>\n<td width=\"297\">\n<p align=\"center\"><b>Matches<\/b><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"297\">\n<p align=\"center\">^<\/p>\n<\/td>\n<td width=\"297\">\n<p align=\"center\">Beginning of line<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"297\">\n<p align=\"center\">$<\/p>\n<\/td>\n<td width=\"297\">\n<p align=\"center\">End of line<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"297\">\n<p align=\"center\">.<\/p>\n<\/td>\n<td width=\"297\">\n<p align=\"center\">Single character; with option m, matches newline too<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"297\">\n<p align=\"center\">[\u2026]<\/p>\n<\/td>\n<td width=\"297\">\n<p align=\"center\">Single character in square brackets<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"297\">\n<p align=\"center\">[^\u2026]<\/p>\n<\/td>\n<td width=\"297\">\n<p align=\"center\">Single character not in square brackets<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"297\">\n<p align=\"center\">\\\\A<\/p>\n<\/td>\n<td width=\"297\">\n<p align=\"center\">Beginning of string<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"297\">\n<p align=\"center\">\\\\z<\/p>\n<\/td>\n<td width=\"297\">\n<p align=\"center\">End of string<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"297\">\n<p align=\"center\">\\\\Z<\/p>\n<\/td>\n<td width=\"297\">\n<p align=\"center\">End of string except allowable final line terminator<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"297\">\n<p align=\"center\">re*<\/p>\n<\/td>\n<td width=\"297\">\n<p align=\"center\">Zero or more occurrences of preceding expression<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"297\">\n<p align=\"center\">re+<\/p>\n<\/td>\n<td width=\"297\">\n<p align=\"center\">One or more occurrences of preceding expression<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"297\">\n<p align=\"center\">re?<\/p>\n<\/td>\n<td width=\"297\">\n<p align=\"center\">Zero or one occurrences of preceding expression<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"297\">\n<p align=\"center\">re{ n}<\/p>\n<\/td>\n<td width=\"297\">\n<p align=\"center\">n occurrences of preceding expression<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"297\">\n<p align=\"center\">re{ n,}<\/p>\n<\/td>\n<td width=\"297\">\n<p align=\"center\">n or more occurrences of preceding expression<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"297\">\n<p align=\"center\">re{ n, m}<\/p>\n<\/td>\n<td width=\"297\">\n<p align=\"center\">At least n, at most m occurrences of preceding expression<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"297\">\n<p align=\"center\">a|b<\/p>\n<\/td>\n<td width=\"297\">\n<p align=\"center\">Either a or b<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"297\">\n<p align=\"center\">(re)<\/p>\n<\/td>\n<td width=\"297\">\n<p align=\"center\">Groups regular expressions; remembers matched text<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"297\">\n<p align=\"center\">(?: re)Scala Regex<\/p>\n<\/td>\n<td width=\"297\">\n<p align=\"center\">Groups regular expressions; doesn\u2019t remember matched text<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"297\">\n<p align=\"center\">(?&gt; re)<\/p>\n<\/td>\n<td width=\"297\">\n<p align=\"center\">Independent pattern; doesn\u2019t backtrack<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"297\">\n<p align=\"center\">\\\\w<\/p>\n<\/td>\n<td width=\"297\">\n<p align=\"center\">Word characters<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"297\">\n<p align=\"center\">\\\\W<\/p>\n<\/td>\n<td width=\"297\">\n<p align=\"center\">Nonword characters<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"297\">\n<p align=\"center\">\\\\s<\/p>\n<\/td>\n<td width=\"297\">\n<p align=\"center\">Whitespace; equivalent to [\\t\\n\\r\\f]<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"297\">\n<p align=\"center\">\\\\S<\/p>\n<\/td>\n<td width=\"297\">\n<p align=\"center\">Nonwhitespace<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"297\">\n<p align=\"center\">\\\\d<\/p>\n<\/td>\n<td width=\"297\">\n<p align=\"center\">Digits; equivalent to [0-9]<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"297\">\n<p align=\"center\">\\\\D<\/p>\n<\/td>\n<td width=\"297\">\n<p align=\"center\">Nondigits<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"297\">\n<p align=\"center\">\\\\A<\/p>\n<\/td>\n<td width=\"297\">\n<p align=\"center\">Beginning of string<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"297\">\n<p align=\"center\">\\\\Z<\/p>\n<\/td>\n<td width=\"297\">\n<p align=\"center\">End of string; matches till before newline, if any<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"297\">\n<p align=\"center\">\\\\z<\/p>\n<\/td>\n<td width=\"297\">\n<p align=\"center\">End of string<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"297\">\n<p align=\"center\">\\\\G<\/p>\n<\/td>\n<td width=\"297\">\n<p align=\"center\">Point where last match ended<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"297\">\n<p align=\"center\">\\\\n<\/p>\n<\/td>\n<td width=\"297\">\n<p align=\"center\">Beck-reference to capture group number \u2018n\u2019<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"297\">\n<p align=\"center\">\\\\b<\/p>\n<\/td>\n<td width=\"297\">\n<p align=\"center\">Word boundaries when outside brackets; backspace (0x08) when inside brackets<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"297\">\n<p align=\"center\">\\\\B<\/p>\n<\/td>\n<td width=\"297\">\n<p align=\"center\">Nonword boundaries<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"297\">\n<p align=\"center\">\\\\n, \\\\t,etc.<\/p>\n<\/td>\n<td width=\"297\">\n<p align=\"center\">Newlines, carriage returns, tabs, and so<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"297\">\n<p align=\"center\">\\\\Q<\/p>\n<\/td>\n<td width=\"297\">\n<p align=\"center\">Escape (quote) all characters up to \\\\E<u><\/u><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"297\">\n<p align=\"center\">\\\\E<\/p>\n<\/td>\n<td width=\"297\">\n<p align=\"center\">Ends quoting begun with \\\\Q<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong><a href=\"https:\/\/data-flair.training\/blogs\/scala-inheritance\/\">Let&#8217;s Learn Scala Inheritance \u2013 Syntax, Example &amp; Types in Detail<\/a><\/strong><\/p>\n<p>So, this was all about Scala Regex Tutorial. Hope you like our explanation.<\/p>\n<h3 class=\"western\">Conclusion<\/h3>\n<p>Hence, in this Scala regex cheat sheet, we studied what is Scala Regular expression. In addition, we saw example &amp; syntax of Scala Regex and how to Replace Matches and\u00a0Search for Groups of Scala Regular Expression. Furthermore, if you have a query regarding, feel free to ask in the comment box.<\/p>\n<p>See Also-\u00a0<strong><a href=\"https:\/\/data-flair.training\/blogs\/scala-final\/\">Scala Final | Scala This<\/a><\/strong><\/p>\n<p><strong><a href=\"https:\/\/en.wikipedia.org\/wiki\/Scala_(programming_language)\">Reference<\/a><\/strong><span hidden class=\"__iawmlf-post-loop-links\" data-iawmlf-links=\"[{&quot;id&quot;:1920,&quot;href&quot;:&quot;https:\\\/\\\/en.wikipedia.org\\\/wiki\\\/Scala_(programming_language)&quot;,&quot;archived_href&quot;:&quot;http:\\\/\\\/web-wp.archive.org\\\/web\\\/20250919075050\\\/https:\\\/\\\/en.wikipedia.org\\\/wiki\\\/Scala_(programming_language)&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2025-12-10 09:49:49&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2025-12-14 06:04:41&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2025-12-17 08:14:32&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2025-12-21 15:16:29&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2025-12-24 20:50:35&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2025-12-27 22:51:06&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-02 00:56:48&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-05 05:12:52&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-08 16:37:57&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-11 16:52:40&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-15 01:28:34&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-19 03:57:54&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-23 15:04:21&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-27 23:53:53&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-31 15:57:47&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-03 17:23:23&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-07 12:58:30&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-10 13:51:06&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-13 14:05:55&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-17 10:42:41&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-20 19:37:04&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-24 11:37:43&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-28 03:48:25&quot;,&quot;http_code&quot;:429},{&quot;date&quot;:&quot;2026-03-03 20:07:22&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-09 03:36:50&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-12 17:53:12&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-16 12:24:01&quot;,&quot;http_code&quot;:429},{&quot;date&quot;:&quot;2026-03-21 16:15:51&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-29 09:06:02&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-02 02:19:02&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-05 07:25:42&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-09 05:45:52&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-13 17:35:26&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-17 20:46:47&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-20 23:10:43&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-24 16:10:49&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-29 02:08:36&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-03 06:35:12&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-07 05:36:56&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-10 12:10:35&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-13 17:35:32&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-18 05:54:28&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-22 04:26:17&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-25 10:55:32&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-29 13:13:25&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-06-01 14:38:15&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-06-05 08:23:46&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-06-09 21:06:00&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-06-13 16:35:11&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-06-18 05:49:58&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-06-22 04:17:29&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-06-26 15:19:02&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-06-29 17:32:11&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-07-03 01:11:06&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-07-06 09:48:22&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-07-10 00:33:28&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-07-13 08:40:54&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-07-16 15:52:40&quot;,&quot;http_code&quot;:200}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-07-16 15:52:40&quot;,&quot;http_code&quot;:200},&quot;process&quot;:&quot;done&quot;}]\"><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In our last tutorial, we studied Scala Trait Mixins.\u00a0Today, we are going to discuss Scala Regular Expressions or in general terms, we call it Scala Regex. In this Scala Regex cheat sheet, we will&#46;&#46;&#46;<\/p>\n","protected":false},"author":6,"featured_media":17940,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[61],"tags":[4343,4372,12539,12540,12541,15943],"class_list":["post-17927","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scala","tag-example-of-scala-regex","tag-example-scala-regex","tag-scala-regex-cheat-sheet","tag-scala-regex-cheatsheet","tag-scala-regex-example","tag-what-is-scala-regex"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.0 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Scala Regex | Scala Regular Expressions - Replacing Matches - DataFlair<\/title>\n<meta name=\"description\" content=\"Scala Regex Tutorial - What is Scala Regular Expressions, Example of Scala Regex, Scala Regular expression Syntax, How to Replace Matches by Scala regex\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/scala-regex\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Scala Regex | Scala Regular Expressions - Replacing Matches - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Scala Regex Tutorial - What is Scala Regular Expressions, Example of Scala Regex, Scala Regular expression Syntax, How to Replace Matches by Scala regex\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/scala-regex\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-06-08T04:10:23+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-12-04T04:45:28+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/06\/Scala-Regex-Regular-Expressions-01.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Scala Regex | Scala Regular Expressions - Replacing Matches - DataFlair","description":"Scala Regex Tutorial - What is Scala Regular Expressions, Example of Scala Regex, Scala Regular expression Syntax, How to Replace Matches by Scala regex","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/scala-regex\/","og_locale":"en_US","og_type":"article","og_title":"Scala Regex | Scala Regular Expressions - Replacing Matches - DataFlair","og_description":"Scala Regex Tutorial - What is Scala Regular Expressions, Example of Scala Regex, Scala Regular expression Syntax, How to Replace Matches by Scala regex","og_url":"https:\/\/data-flair.training\/blogs\/scala-regex\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2018-06-08T04:10:23+00:00","article_modified_time":"2021-12-04T04:45:28+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/06\/Scala-Regex-Regular-Expressions-01.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/scala-regex\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/scala-regex\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/2c58ecb4f73a39f0ef993f1ddfcd7b89"},"headline":"Scala Regex | Scala Regular Expressions &#8211; Replacing Matches","datePublished":"2018-06-08T04:10:23+00:00","dateModified":"2021-12-04T04:45:28+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/scala-regex\/"},"wordCount":604,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/scala-regex\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/06\/Scala-Regex-Regular-Expressions-01.jpg","keywords":["Example of Scala Regex","Example Scala Regex","Scala Regex cheat sheet","Scala Regex cheatsheet","Scala Regex Example'","What is Scala Regex"],"articleSection":["Scala Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/scala-regex\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/scala-regex\/","url":"https:\/\/data-flair.training\/blogs\/scala-regex\/","name":"Scala Regex | Scala Regular Expressions - Replacing Matches - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/scala-regex\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/scala-regex\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/06\/Scala-Regex-Regular-Expressions-01.jpg","datePublished":"2018-06-08T04:10:23+00:00","dateModified":"2021-12-04T04:45:28+00:00","description":"Scala Regex Tutorial - What is Scala Regular Expressions, Example of Scala Regex, Scala Regular expression Syntax, How to Replace Matches by Scala regex","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/scala-regex\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/scala-regex\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/scala-regex\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/06\/Scala-Regex-Regular-Expressions-01.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/06\/Scala-Regex-Regular-Expressions-01.jpg","width":1200,"height":628,"caption":"Scala Regex | Scala Regular Expressions"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/scala-regex\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Scala Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/scala\/"},{"@type":"ListItem","position":3,"name":"Scala Regex | Scala Regular Expressions &#8211; Replacing Matches"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/2c58ecb4f73a39f0ef993f1ddfcd7b89","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"The DataFlair Team provides industry-driven content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our expert educators focus on delivering value-packed, easy-to-follow resources for tech enthusiasts and professionals.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam2\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/17927","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=17927"}],"version-history":[{"count":6,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/17927\/revisions"}],"predecessor-version":[{"id":104742,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/17927\/revisions\/104742"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/17940"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=17927"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=17927"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=17927"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}