Forum Replies Created
-
AuthorPosts
-
Peter KahrelParticipantOnly after copying your sample did I discover what went wrong. (It did work, by the way, but not correctly — it’s always helpful to indicate in what way something doesn’t work.) Your sample has a return between the two paragraphs and a space before that return, so in the expression I gave started matching the return and/or rogue space character. This expression should fix that:
^(.+?)(.+?)(?=)stands for ‘horizontal space’, so it matsches all spaces except the hard return. And I added (?=) so that the expression doesn’t match the space after the second word.
P.
Peter KahrelParticipant^(.+?)(.+?)^ from the start of a paragraph
(.+?) capture characters
up to the first space
(.+?) capture characters after the space
up to the second spaceRefer to the first word (in the Change to field) using $1, the second word, $2
Peter
Peter KahrelParticipantMaybe show some examples of what you have and how they should be changed.
Peter KahrelParticipantI don’t see that error, and I use that script a lot. Try this: close all your documents so that just the book file is open, then run the script.
Peter KahrelParticipantStrange, I copied the string from your original post and the Grep expression I suggested, and it works fine for me: the matches I get are “jim q. public, MD” and “Jill Neigh Bor,MD”. That’s correct, isn’t it? If it is, could you check the expression you used?
As to
[^;]+, ^ inside a character class means ‘not’. So[^;]+means ‘mustn’t match a ; and the whole expression paraphrases as ‘match from ; up to * with no ; in between ; and *’.
Peter KahrelParticipantThis is a tricky one. First of all, you need to escape the asterisk in your lookahead: use
(?=\*), not(?=*)(because you’re after the * character literally, you don’t want to use it as an operator).But when you’ve fixed that you’ll find that the expression matches “jim q. public, MD” (as expected) and “Cindy E. Verybody, MD; Jill Neigh Bor,MD” (not expected). What you need to do is match from
;to*without any intervening;. You can do that with this expression:(?<=;)[^;]+?(?=\*)
Peter
Peter KahrelParticipantAssuming that two consecutive words with initial capitals are names, you can do what you want with two GREP expressions:
1. ‘Paul’ followed by and and another name:
\u+(?=\u+\u)This one reads ‘find a name \u+ followed by (?= a space and a name \u+ followed by a space and a name.
2. Then find Sue Craft:
\u+\u+The naive assumption is that a name is matched by an upper-case letter followed by any lower-case letters, which is too simple, so you’ll have to refine the pattern to include double-barrelled names, prefixes, etc.
Peter
Peter KahrelParticipantMaybe set the paragraph to start in the next frame (or column).
Peter KahrelParticipantUnfortunately you can’t set a fixed space in the automatic number. I’d have thought that “Map^S^H.^1:.” would do it, but it doesn’t. You could do a Grep replacement, looking for
(?<=Map) (?=\d)and replacing with~S. In the Find Format panel, set the character and/or paragraph style used for cross-reference (if any).
Peter KahrelParticipantSomething like this:
versionNumber = ''; descr = app.activeDocument.metadataPreferences.description; if (descr !== '') { version = descr.match (/ver=([\d.]+)/); if (version !== null) { versionNumber = version[1]; } }Get the description field from the document’s metadata object
Match digits and dots following ‘ver=’
If there is a match, it’s an array, you want item 1Peter
February 21, 2016 at 1:11 pm in reply to: GREP to insert a full stop at the end of paragraphs #82152
Peter KahrelParticipantSo the question is, why doesn’t it work for you?
(If only one could edit one’s messages. . .)
February 21, 2016 at 1:10 pm in reply to: GREP to insert a full stop at the end of paragraphs #82151
Peter KahrelParticipant> The dot in your [^.] matches any character. To match just a dot in the text, use \.
Which is complete nonsense, because the dot is in a character class so that there’s no need for the backslash. Now that I tried your original
([^.])\rand$1.\rI find that they work fine over here. Though I still think that $ is better than \r, so use([^.])$and$1.February 21, 2016 at 3:51 am in reply to: GREP to insert a full stop at the end of paragraphs #82143
Peter KahrelParticipantSamuel,
You were very close. Instead of
([^.])\r, use([^\.])$.The dot in your [^.] matches any character. To match just a dot in the text, use \.
Also, if you use \r you won’t match the last paragraph in a story if the story doesn’t end in an empty paragraph. $ matches the end of the paragraph even when it’s not followed by a return character.Colleen: using ^p (or \r for that matter) in replacements can lead to strange results at points where the paragraphs before and after the ^p have different paragraph styles.
Peter KahrelParticipantWhat do you mean by ‘paste into the text field again’? That the frame becomes an inline? If what you select is on a single line, then the script below would do it. Select some text, all on one line, and run the script.
(function(){ var width = app.selection[0].endHorizontalOffset - app.selection[0].horizontalOffset; var frame = app.selection[0].textFrames.add(); app.selection[0].move (LocationOptions.AFTER, frame.insertionPoints[0]); var gb = frame.geometricBounds; gb[3] = gb[1]+width frame.geometricBounds = gb; }());Peter
-
AuthorPosts
