Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
"my 1980" or "my1980"?
Copy link to clipboard
Copied
Good my1980
(?<=Good my) 1980
By @dublove
You don't need the space after the bracket.
(?<=Good my)1980
Copy link to clipboard
Copied
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)
Copy link to clipboard
Copied
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}