Skip to content
Advertisement

How to convert string into regex with the words more than 3 character?

I am trying to create a ABRV from string. I can achieve some result , but not the final expected one. For example, if I have INTERNATIONAL Monetary Fund ltd string, I need to get IMF from it.

I have tried this one, but it only returns IMFl. I need to restrict it to count only words with more than 3 characters.

JavaScript

This one doesn’t work as expected

JavaScript

Advertisement

Answer

To only capture the first letters of words of 4 or more characters, you can use a lookahead for 3 or more word characters after matching the first character:

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