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\>
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
Copy link to clipboard
Copied
Hi,
Please share the your requirement-screenshot or your code?
Thanks
KS
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.
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
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");
Copy link to clipboard
Copied
With 'JavaScript' I meant the JavaScript string functions, such as str = str.replace (/\b\w+\b/g, '')
P.