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

Anybody know why this grep regex doesn't work?

Engaged ,
Oct 15, 2025 Oct 15, 2025

I'm trying to find periods with zero or more whitespace characters after them. Everything I can find says this should work, but it doesn't work for strings that have no whitespace (looking for a capital letter followed by a period):

 

var capitalExpression = "^[A-Z]\\.\\s*";
 
This finds
A. Start the engine.
 
but not
A.Start the engine.
TOPICS
Scripting , UXP Scripting
946
Translate
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 2 Correct answers

Community Expert , Oct 15, 2025 Oct 15, 2025

I don't think that the problem is with your query. Maybe something else is going on somewhere else in your script? Your query seems to work for me, at least when I put it in the simplest script possible:

 

thomas.gif

 

 

Translate
Community Expert , Oct 16, 2025 Oct 16, 2025

Hi @Thomas_Calvin , It’s also working for me with ExtendScript. Here it is via a function:

 

grepSearch("^[A-Z]\\.\\s*", "B. ")

/**
* Document Grep find and change 
* @ param f the find grep string 
* @ param c the change grep string
* @ return void 
*/
function grepSearch(f,c){
    app.findGrepPreferences = app.changeGrepPreferences = app.findChangeGrepOptions = null;
    app.findChangeGrepOptions.properties = app.findChangeGrepOptions.properties = {includeFootnotes:true, includeHiddenLayers:
...
Translate
Community Expert ,
Oct 15, 2025 Oct 15, 2025

How about:

 

\u\.\s*

 

2025-10-15_17-59-03 (1).gif

 

~Barb

Translate
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 ,
Oct 15, 2025 Oct 15, 2025

Oh darn. I focused on your GREP expression as per your title, and missed that you need this included in a script. Not sure that my answer will be helpful. Sorry!

 

~Barb

Translate
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 ,
Oct 15, 2025 Oct 15, 2025

I appreciate it Barb! I have a working script and a mostly-working expression. But the asterisk doesn't work.

Translate
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 ,
Oct 16, 2025 Oct 16, 2025

It turns out that the UXP dev tool wasn't reloading the script when saved, despite "watch" being on. Restarting everything fixed it and the asterisk works fine!

Translate
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 ,
Oct 15, 2025 Oct 15, 2025

The ens should be \\s+? I think

Translate
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 ,
Oct 15, 2025 Oct 15, 2025

Thanks for the reply. Everything I've looked at says + means "one or more" not zero or more.

Translate
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 ,
Oct 15, 2025 Oct 15, 2025

I don't think that the problem is with your query. Maybe something else is going on somewhere else in your script? Your query seems to work for me, at least when I put it in the simplest script possible:

 

thomas.gif

 

 

Translate
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 ,
Oct 16, 2025 Oct 16, 2025

Yep, thanks. It turns out that it works fine for me too. The UXP developer tool neglected to reload the source after I changed and saved it, despite "watch" being on. Usually this works fine. I noticed the wrong expression being used when stepping through with the debugger.

Translate
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 ,
Oct 15, 2025 Oct 15, 2025

Noticed you tagged 'UXP Scripting' - are you writing a UXP script? 

It might need to be something like this

/^[A-Z]\.\s*/
Translate
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 ,
Oct 16, 2025 Oct 16, 2025

It is a UXP script. A plug-in, in fact.

Translate
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 ,
Oct 16, 2025 Oct 16, 2025

Hi @Thomas_Calvin , It’s also working for me with ExtendScript. Here it is via a function:

 

grepSearch("^[A-Z]\\.\\s*", "B. ")

/**
* Document Grep find and change 
* @ param f the find grep string 
* @ param c the change grep string
* @ return void 
*/
function grepSearch(f,c){
    app.findGrepPreferences = app.changeGrepPreferences = app.findChangeGrepOptions = null;
    app.findChangeGrepOptions.properties = app.findChangeGrepOptions.properties = {includeFootnotes:true, includeHiddenLayers:true, includeMasterPages:true, wholeWord:false}  
    app.findGrepPreferences.findWhat = f;
    app.changeGrepPreferences.changeTo = c;
    app.activeDocument.changeGrep( true )
}

 

 

Screen Shot.png

 

Screen Shot 1.png

Translate
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 ,
Oct 16, 2025 Oct 16, 2025

Thanks Rob.

In the end, it works fine. The UXP developer tool did not pick up my source-code changes for some reason (despite "watch" being on), and was running an old version that didn't have the asterisk.

Translate
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 ,
Oct 16, 2025 Oct 16, 2025

Yes, you found out the hard way that the UXP developer tool can't save changes you made to the code. It's pretty awful, but that's the way it is.

Translate
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 ,
Oct 16, 2025 Oct 16, 2025

Actually, it usually does reload immediately after I save the file in VS Code. This is the first time I've seen it fail at that.

 

The really offensive part is the fake "editor" the UXP tool presents and allows you to "edit" and "save" the file in. This is mind-boggling. Why do they deliberately waste customers' time with this? There's no excuse for it.

Translate
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 ,
Oct 17, 2025 Oct 17, 2025
LATEST

Join the crowds. Here you can vent your ire:

https://forums.creativeclouddeveloper.com/c/uxp-developer-tool/65

 

And here you can log bugs and feature requests:

https://indesign.uservoice.com

 

Translate
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