2021年4月8日星期四

Why regex extract return wrong value in scala

val pattern = "[A-Z]{2,3}[0-9]{4}".r  val extractedData =  pattern.findFirstIn("ABCD1234")  

I have the above code to look for the valid data. If my string is DTD0001, it should be correct. But when I have ABCD1234, it will return BCD1234, which is incorrect. Suppose it will not return anything.

I want to make it return value only when it has 3 letters + 4 digits. otherwise don't return any value. How to make this correct?

https://stackoverflow.com/questions/67014452/why-regex-extract-return-wrong-value-in-scala April 09, 2021 at 10:54AM

没有评论:

发表评论