Copy link to clipboard
Copied
Hi All,
I need find the " + " symbol between two ampersand symbols. I will tried the grep code and find the all text in my Doc.
used grep code: \&.+?\&
Example: [&~NOSTYLE~ + {~NOSTYLE~[TimesTen Italic%P%100.0]+~rom~~norm+~&]
How to find the plus symbol inside the ampersand symbol(&) ?
Thanks,
Prabu G
In that case you need to find all instances of the code fragments, then replace + with |+|. Something like this:
app.findGrepPreferences = null;
app.findGrepPreferences.findWhat = '\\[&.+?&\\]';
found = app.documents[0].findGrep();
for (i = found.length-1; i >= 0; i--) {
found.contents = found.contents.replace (/\+/g, '|+|');
}
Untried, but you get the picture.
P.
Copy link to clipboard
Copied
You should escape the +, no need to escape the ampersands: &\+& will do.
P.
Copy link to clipboard
Copied
Hi Prabu,
Very simply (including the opening/closing brackets):
(\[&|\G).*?\K\+(?=.*&\])
(^/) [ advanced Grep code -- To be validated! ]
Copy link to clipboard
Copied
Hi Peter and Obi,
Thanks for your reply.
sorry for the above....
Am working with ASCII code for powerMath equation. so i need to find inside the ASCII codes([&......&]) "+"(only) symbol and change to "|+|".
Thanks,
Prabu G
Copy link to clipboard
Copied
In that case you need to find all instances of the code fragments, then replace + with |+|. Something like this:
app.findGrepPreferences = null;
app.findGrepPreferences.findWhat = '\\[&.+?&\\]';
found = app.documents[0].findGrep();
for (i = found.length-1; i >= 0; i--) {
found.contents = found.contents.replace (/\+/g, '|+|');
}
Untried, but you get the picture.
P.
Copy link to clipboard
Copied
Hi Peter,
Amazing. Simply amazing. Works like a charm now in every instance.
Thanks
prabu G
Copy link to clipboard
Copied
Prabu,
Do you mean mine not?
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = "(\\[&|\\G).*?\\K\\+(?=.*&\\])";
app.changeGrepPreferences.changeTo = "|+|";
app.activeDocument.changeGrep();
(^/)
Copy link to clipboard
Copied
Very nice, Michel. Didn't know about \G
P.
Copy link to clipboard
Copied
Only some Jedis know it! [it comes from the Dark Side]
I gave it a name: the \Ghost!
(^/)
Copy link to clipboard
Copied
Hi Prabu,
Keep in mind there are still possible issues in using (\[&|\G).*?\K\+(?=.*&\])
as it doesn't fully deal with extra + signs.
For example in the text:
X+Y+[&A+B+C+D&]+X+Y[&A+B&]+X+&]+[&X¶
+A&]+B[&X+Y&]+[&X+Y++Z&]++C+D&]¶
we may expect GREP to alter only the well-formed red areas. But it won't be the case with uncontrolled .*
in your regex.
So, in your find/change script you might need to refine the suggested syntax,
const GREP1 = "(\\[&|\\G).*?\\K\\+(?=.*&\\])";
// etc.
into something more explicit like
const GREP2 = "(\\[&|\\G)[^&+\\r]+\\K\\++(?=[^&\\r]+&\\])";
// etc.
Given the same input, the figure below shows how the + signs are captured and changed (see the red crosses ×) using GREP1
vs. GREP2
. You can see that GREP1
eats a number of + signs which are not embedded in the [&…&] regions, while GREP2
is a bit more accurate:
But of course there is no definitive answer as long as we don't have more specification on the actual characters your stream may contain inside and outside the markup.
@+
Marc
Copy link to clipboard
Copied
Marc -- When you use the single-line modifier (?s) the dot matches the return character, which gets around the problem you noted that the original grep expression doesn't deal with internal line breaks.
P.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now