简体   繁体   English

Scala:带字符串插值的正则表达式匹配

[英]Scala: regex with string interpolation for match

I have two regex that I want to merge in one final regex to match text against this. 我有两个正则表达式,我想在一个最终的正则表达式中合并以匹配文本。 Is there a way to get it with string interpolation or the right way is different? 有没有办法用字符串插值来获得它或正确的方式是不同的?

val regex1 = "....".r
val regex2 = "....".r

val finalRegex = "^($regex1)(?:($regex2))$".r

is that possible? 那可能吗?

试试这个。

val finalRegex = s"^(${regex1.regex})(?:(${regex2.regex}))$$".r

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM