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

Grep help

Engaged ,
Sep 23, 2016 Sep 23, 2016

Copy link to clipboard

Copied

How would I get this GREP to find repeated words which may also be hyphenated?

\<([a-z|A-Z]+)\> \<\1\>

TOPICS
Scripting

Views

370

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

correct answers 1 Correct answer

Community Expert , Sep 23, 2016 Sep 23, 2016

Don't use alternative inside character classes. Use whis to match words that can be hyphenated:

\b([-A-Za-z]+)\b

(\< and \> work in InDesign but not in JavaScript. \b works in both.)

Peter

Votes

Translate

Translate
Contributor ,
Sep 23, 2016 Sep 23, 2016

Copy link to clipboard

Copied

Hi,

Please share the your requirement-screenshot or your code?

Thanks

KS

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
Engaged ,
Sep 23, 2016 Sep 23, 2016

Copy link to clipboard

Copied

Are you doing this in scripting or in the find/change dialog box?? If scripting, all the backslashes need to be escaped. If not then it's fine; you just need to add a possibility of a hyphen -? between two sets of letters.

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 ,
Sep 23, 2016 Sep 23, 2016

Copy link to clipboard

Copied

Don't use alternative inside character classes. Use whis to match words that can be hyphenated:

\b([-A-Za-z]+)\b

(\< and \> work in InDesign but not in JavaScript. \b works in both.)

Peter

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
Engaged ,
Sep 23, 2016 Sep 23, 2016

Copy link to clipboard

Copied

pkahrel wrote:

(\< and \> work in InDesign but not in JavaScript. \b works in both.)

Can you provide an example?? I tried to recreate this but for me both cases work:

app.findGrepPreferences = app.changeGrepPreferences = null;

app.findGrepPreferences.findWhat = "\\<and\\b";

app.changeGrepPreferences.changeTo = "AND";

app.changeGrep();

Except when scripting without using Find/Change preferences.. Then neither worked:

if(app.selection[0].contents == "\bAND\b");

alert("YES");

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 ,
Sep 23, 2016 Sep 23, 2016

Copy link to clipboard

Copied

LATEST

With 'JavaScript' I meant the JavaScript string functions, such as str = str.replace (/\b\w+\b/g, '')

P.

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