Validatiing the URL using regex validation

(Asit_Tiriya) #1

Hello,
I have been trying to validate a URL for a certain keyword matches like -
www.sample.com/API/
www.example.com/API/

basically, I need to check two things, it should start with www. and have an /api/ section

The regex is working fine when I check with regexr but I am getting errors of -
Your regular expression can take too much time to complete, please use another one.

Could you please verify this -
/(?:http(s)?://)?[\w.-]+(?:.[\w.-]+)+[/]API/g

and suggest me the right regex.

(Karen Barker) #2

Hi there,

I think it’s the number of quantifiers here that are causing the issue. However, this regex seems to work and should do the trick for you:

(http://www.|https://www.|http://|https://)?[\w.-]+[/]API/+

:thumbsup: