Quantcast
Channel: Adobe Community : Popular Discussions - Photoshop Scripting
Viewing all articles
Browse latest Browse all 12244

Regex: since no negative look behind, what is the best way ...

$
0
0

I have a great Photoshop scripting routine that uses regular expressions to find all of the parts of a string that are surrounded by underlines.

 

Regex:  /_([\s\S]*?)_/g

 

Text:  Match on _this_ and also _on this_ and even _on this too_.

 

... and life was nice, until my paragraph contained a URL that had underlines in it!

 

Now, I want to make sure that if I match on an underline, it isn't an underline within a URL.

 

I know that URLs don't have spaces, so I modified by regular expression to say "when you find a match, look back to see if there is an http without at least one space between it and the match".

 

Regex: /(?<!http) +_([\s\S]*?)_/g

 

Text: Match on _this_ and also _on this_ but if http://mysite.com/more_url.with?underscores_then.no.match until after you _leave the URL_.

 

... but alas, it appears that this implementation of Javascript doesn't support negative look behind.

 

So, can anyone think of an elegant regular expression that matches on parts of a string that are surrounded by underscores, unless they are within a URL?

 

    - Brad


Viewing all articles
Browse latest Browse all 12244

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>