Skip to main content
Legend
March 26, 2019
Question

RegExp problem

  • March 26, 2019
  • 2 replies
  • 1260 views

Hey.

If here is a RegExp guru?

I rarely use RegExp myself.

Who knows why in photoshop does not work Negative Lookbehind (?<!...)

And how to make an analog?

var s = "123abc123aac"

alert( s.search(/(?<!ab)c/) )

I want this alert to say 11.

This topic has been closed for replies.

2 replies

Kukurykus
Legend
March 26, 2019

I am just a little guru and found Photoshop RegEx implementation is very lame. It was sometimes corrected with another releases, but generally it has own broken rules. I also had some problem with 'search', maybe it's related to your problem:

RegExp search bug - PS-SCRIPTS.COM

Stephen Marsh
Community Expert
Community Expert
March 26, 2019

The great thing about regex is that there are many valid answers to the same problem. This is just what I came up with first. I like capture groups and back references, there will of course be other ways to the same answer.

So if the pattern is to return the first digit at the beginning of the string, then skip 2 digits, skip 3 alphas, return the next digit, then skip everything else thereafter...

var s = "123abc123aac" 

alert(s.replace(/(^\d)(?:\d{2}\D+)(\d)(?:.+)/,"$1$2"));

r-binAuthor
Legend
March 26, 2019

No, I need exactly this

(?<!foo)bar finds the 2nd bar ("bar" which does not have "foo" before it)

pixxxelschubser
Community Expert
Community Expert
March 26, 2019

So you need the position of the "c" which does not have "ab" before?

Please give some more examples. And what is if there more "c"s exists in one string?