Quantcast
Channel: Adobe Community: Message List - InDesign
Viewing all articles
Browse latest Browse all 143383

Re: grep? find & replace after 8 characters

$
0
0

Here's a sort of plain-English translation of the various strings to help you.

 

^(\w{8})(\..+?)(\r) : ^ means the start of a paragraph here (it means other things in other palces, so try not to get too confused. ) The panetetical groups are marking subexpressions to allow you to re-use chunks of what is found. \w{8} means find any word character (which is pretty much anything alphanumeric) 8 times, or any sting of 8 word characters, and the ^ meant it was the first 8 characters inthe paragraph. \..+? is a literal period (adding the backslash in front of it ("escaping" it) makes it literal, followed by any srting of one or more characters (.+) and the ? is supposed to make it choose the shortest match, but it isn't 100% foolproof (didn't work for me in my testing here). the \r is a paragraph return, so the whole thing is find the first 8 characters, then everything else upt to a return, and the return. The change to expression $1$3 means use the found text in the first and third subexpressions that were marked off with the parentheses, or the first 8 characters and the return, but throw out everything in between.

 

\..*$ is very similar, but I'm onl;y looking at the end of the paragraph. In this case the $ is a location marker that means the end of the paragraph, so \. is a period, followed by .* which is any character 0 or more times, up to the end of the paragraph, so it doesn't care about anythingbefor the first period, and it matches right up to the return, but doesn't include it, so if you replace leave the cahnge field blank (replace with nothing) it deletes everything from the first period to the end of the paragraph. In this case I think the * is preferable to the + because it removes the period evenif there is nothig following it at the end of the paragraph.

 

\.[^.]*$ uses a "negative class" to fix the problem that the ? didn't limit the found text in testing to only the last period and what followed. Square brakets are used to define a class -- a group of characters any one of which is a match, sort of a selective wildcard -- and the ^ inside the class is a negative marker, so this class is anything that isn't a period (inside the class the . is literal and does not need to be escaped). the * again is 0 or more times, and the $ is the end of paragraph location, so it looks for a period followed by anyting that isn't aperiod at the end of the paragraph. Again, leave the change field blank.

 

If you really would like to learn more about GREP, you can't go wrong buying Peter Kahrel's $10 ebook, GREP in InDesign CS3/4 from O'Reilly.


Viewing all articles
Browse latest Browse all 143383

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>