• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers

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

Contributor ,
Dec 01, 2022 Dec 01, 2022

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?

TOPICS
Bug , How to , Performance , Scripting

Views

211

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 01, 2022 Dec 01, 2022

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.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 01, 2022 Dec 01, 2022

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Dec 01, 2022 Dec 01, 2022

Copy link to clipboard

Copied

"my 1980" or "my1980"? 

 

ID-Tasker - most powerful tool ever created for InDesign

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 01, 2022 Dec 01, 2022

Copy link to clipboard

Copied

quote

Good my1980

(?<=Good my) 1980


By @dublove

You don't need the space after the bracket. 

(?<=Good my)1980

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 01, 2022 Dec 01, 2022

Copy link to clipboard

Copied

LATEST

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}

 

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines