Skip to main content
dublove
Legend
December 1, 2022
Question

How to use regular expression to reverse search, and limit more than two conditions

  • December 1, 2022
  • 5 replies
  • 452 views

How to use regular expression to reverse search, and limit more than two conditions

For example, my text is as follows:
Good abc1980
Good ace1980
Good abc1988
Good my1980

------------
I just want to find: “Good” in "Good abc1980"
I use regular: Good (?=\sabc1980)
It can be found.

Conversely, I want to find "1980" in "Good my 1980"
I use regular: (?<=Good my) 1980
The result was failure.

How to solve this problem?

This topic has been closed for replies.

5 replies

pixxxelschubser
Community Expert
Community Expert
December 1, 2022

Generally speaking - this is how it should be found in all the examples shown.

first:

Good(?=\h\w{2,3}\d{4})

second:

Good\h\w{2,3}\h?\K\d{4}

 

 

Community Expert
December 1, 2022
quote

Good my1980

(?<=Good my) 1980


By @dublove

You don't need the space after the bracket. 

(?<=Good my)1980

dublove
dubloveAuthor
Legend
January 25, 2024

@Eugene Tyson 

What I want to say is that regularization only supports

(?<=G) 1980

But it does not support two or more characters on the left side

(?<=Good my) 1980

 

However, this is also supported, on the right side, there can be more than one character

1980 (?<=Good my)

Robert at ID-Tasker
Legend
December 1, 2022

"my 1980" or "my1980"? 

 

m1b
Community Expert
Community Expert
December 1, 2022

Actually now that I've thought about it, the problem is very likely that RegExp in JavaScript (including ExtendScript) does not support positive lookbehinds. You can use findGrep() instead, which does support it. Search for a script example that used findGrep. 
-Mark

m1b
Community Expert
Community Expert
December 1, 2022

Hi @dublove, are you doing a grep search via the UI or via ExtendScript? If via script please post the section of code and we will get to the bottom of it.