0
pattern_for_links = /
        (((((http|ftp|https):\/{2}|([0-9a-z_-]+\.)+)|)(([0-9a-z_-]+\.)+(com)(:[0-9]+)?
        ((\/([~0-9a-zA-Z\#\+\%@@\.\/_-]+))?(\?[0-9a-zA-Z\+\%@@\/&\[\];=_-]+)?)?))\b)
                    /gmi;

And I get this match (JS) which is fine and all matches correct:

http://www.yahoo.com 
yahoo.com/wordss
www.yahoo.com

But when I add / at the end, then / is not included (/ not matched).

http://www.yahoo.com/
yahoo.com/wordss/
www.yahoo.com/

How can I also include / at the end, using pattern_for_links?

EDIT

Solution: I added \b\/? instead of only \b, and now / also matched and included.

Paul T. Rawkeen
  • 3,994
  • 3
  • 35
  • 51
lowdegeneration
  • 359
  • 5
  • 13

1 Answers1

0

Try this:

/(https?:\/\/(www\.)?)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&\/=]*)/gmi

Taken from Regex for URL: SO, with slight modification to catch both http/https prefixed URLs, and URLs without them.

Also, for a quick and easy RegEx making (and learning), see RegExr.com

code
  • 2,115
  • 1
  • 22
  • 46