Saturday, December 31, 2016

InDesign GREP everything between two consecutive returns and a digit(or)return


Say I have some text in the following format:


Text before formatting


What I am trying to style, using GREP, is the beginning of every new paragraph (that comes after an empty line), until a digit or return is reached, so that it would look something like this:



Text after formatting


I've been using regexr to try and find a solution, but it appears not be 100% compatible with InDesign's GREP utility.



Answer



Updated Answer:


The problem is that using a paragraph break for every new line means that every line is a paragraph and using GREP paragraph styles you can only target a single paragraph. Theres no way to tell if you are on the first line because every line is the first line. The only way to get around that would be to test if the paragraph before is empty.. which I don't think is possible.


If changing the paragraph breaks to soft breaks you can use this:


(?

If changing the breaks isn't an option I havn't got a workaround for the paragraphs without numbers but you can target just the ones with using this:


^.*?(?=\d)




Original Answer:


^.*?(?=\d|\n)

An explanation -


^ matches the beginning of the paragraph


. matches any character


*? matches 0 or 1 time (so we only match up to the first digit)


(?=) looks ahead (matches up to but not including what's in the parenthesis)



\d matches any digit


| OR


\n matches a line break




For reference, All of this can be found on the InDesign help.


No comments:

Post a Comment

technique - How credible is wikipedia?

I understand that this question relates more to wikipedia than it does writing but... If I was going to use wikipedia for a source for a res...