0
([^("|'|>)])((http(s)?:\/\/|www\.)[A-Z0-9._%+\-\/]*)(?!["|'])

I am using the above on the following text:

this is the world truning at the ground level https://en.wikipedia.org/wiki/American_Standard_Code_for_Information_Interchange this is the world truning at the ground level
this is the world truning at the ground levelthis is the world truning at the ground levelthis is the world truning at the ground levelthis is the world truning at the ground levelthis is the world truning at the ground levelthis is the world truning at the ground levelthis is the world truning at the ground levelthis is the world truning at the ground levelthis is the world truning at the ground levelthis is the world truning at the ground levelthis is the world truning at the ground level http://desktop.com
http://desktop.com http://desktop.com ahsdjhaldhjashdk

If I use this regex on the passage above, I get all the links but with a preceeding space. I need a REGEX that checks the condition that I have but select the preceeding space.

I have the preceding check of ([^("|'|>)]) as I need that if I the following text of:

<a href="http://desktop.com/" target="_blank" data-mce-href="http://desktop.com">http://desktop.com</a>

Then none of the URLS in this get selected.

bobble bubble
  • 16,888
  • 3
  • 27
  • 46
Bhumi Singhal
  • 8,063
  • 10
  • 50
  • 76
  • What if you replace your `([^("|'|>)])` with `(\b)` – Adam Jan 22 '16 at 10:30
  • No, you do not need `([^("|'|>)])`, you need to parse the anchor node value from HTML with DOM. Then, you won't have this trouble. Just collect all text nodes, and then collect the links if you do not want URLs from inside tags (e.g. attributes). – Wiktor Stribiżew Jan 22 '16 at 10:32
  • However, I guess you are looking for [this](https://jsfiddle.net/938vLpmp/). – Wiktor Stribiżew Jan 22 '16 at 10:39
  • @WiktorStribiżew actually i after identifying the URLS, i need to convert them into a link. – Bhumi Singhal Jan 22 '16 at 10:59
  • @Adam : \b wasnnt working .. can you please provide the regex? – Bhumi Singhal Jan 22 '16 at 11:00
  • See [Auto-link URL with javascript Regex (no libraries)](http://stackoverflow.com/questions/29747733/auto-link-url-with-javascript-regex/29747837#29747837). Please let me know if that works for you. Besides, you might want to check [3rd party libraries](http://stackoverflow.com/a/21925491/3832970). – Wiktor Stribiżew Jan 22 '16 at 11:07

1 Answers1

0
var re = /(?![^<]*>|[^<>]*<\/(?!(?:p|pre)>))((https?:)\/\/[a-z0-9&#=.\/\-?_]+)/gi;

Worked. This can be found in a post here.

Community
  • 1
  • 1
Bhumi Singhal
  • 8,063
  • 10
  • 50
  • 76