Skip to content
Advertisement

Why regex extract return wrong value in scala [closed]

JavaScript

I have the above code to look for valid data.

Input:

JavaScript

Expected Output:

JavaScript

Input:

JavaScript

Expected Output:

i.e. nothing.

Currently, it is returning BCD1234 which is incorrect.

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?

Advertisement

Answer

findFirstIn() returns the first sub-string that matches the pattern. If you don’t want a sub-string, but just to test for a match, then that’s not the tool you want to use.

JavaScript

If you want to extract a matching word from a longer string then you need to incorporate the word boundaries into your pattern.

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement