Find duplicate webaddress through regex

30 Views Asked by At

If someone types webadress twice by wrongly i want to find the duplicate webaddress using regex. Example:

http://stackoverflow.com/questions/ask/advice?http://stackoverflow.com/questions/ask/advice?

It should throw an error.

I check the rule \b(\w+)\s+\1\b, it's not working for me.

Can someone help me to find the rule?

1

There are 1 best solutions below

3
Jonathan Mee On

This won't work because (\w+) is just for characters.

Looks like you want to search for non-whitespace characters in a string that starts with "http://"

You could do that like this: \b(http://\S+)\s*\1