I try to apply character style with grep via script. I have a textframe with text shown below:
Iquatusdae quiberum, sitatem pellabo reriatio que volupta temolestrum exerovi delesseque omniate nonecta turitia diti arum venis am as minim am ut exces rem <b>blabla</b> quo offici dolupta tureperum ipsus dolor aut assus, ipient laudae coreictati volecest aut aditium nonsed ut etur sam nimporestem www.facebook.com et velit aut offictas res inctotat etur, soluptat la velest am imporemporem serioreicte reped quo ma
if I run script below (textframe is selected at start and character syle "bold" does exists!) everything is OK, string <b>blabla</b> is formated as I want!
myStory=app.selection[0].parentStory;
app.findGrepPreferences = NothingEnum.nothing;
app.changeGrepPreferences = NothingEnum.nothing;
app.findChangeGrepOptions.includeFootnotes = false;
app.findChangeGrepOptions.includeHiddenLayers = false;
app.findChangeGrepOptions.includeLockedLayersForFind = false;
app.findChangeGrepOptions.includeLockedStoriesForFind = false;
app.findChangeGrepOptions.includeMasterPages = false;
app.findGrepPreferences.findWhat = "(?s)<b>(.+?)</b>";
app.changeGrepPreferences.appliedCharacterStyle =app.activeDocument.characterStyles.item("bold") ;
myStory.changeGrep();
app.findGrepPreferences = NothingEnum.nothing;
app.changeGrepPreferences = NothingEnum.nothing;
But if I use expression w{3}.?\S+|http://.+\S+ which should find some urls and apply character style "bold" nothing happens. Expression is not perfect for searching all urls but it works if i use Find/Change in application.
If that is the exact same expression as you are using in your script, then the solution is simple: use double backslashes.
Thank you, that helped.
Some further information:
This has nothing to do with GREP and all with Javascript. In Javascript text strings, the backslash is an escape character -- stuff like "\r", "\t", and "\u2212" all works as one would think. The string itself, which needs to be transfered to ID's GREP Find, only needs a single backslash "\S" but because the string is passed through using JS, you need to enter two of 'em.
mumble mumble regexp literals mumble mumble
/foo\.bar/.source