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

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

Enthusiast ,
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

307

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.

Votes

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

Votes

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

"my 1980" or "my1980"? 

 

Votes

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

Votes

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
Enthusiast ,
Jan 25, 2024 Jan 25, 2024

Copy link to clipboard

Copied

LATEST

@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)

Votes

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

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}

 

 

Votes

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