{"id":1861,"date":"2014-11-07T13:18:23","date_gmt":"2014-11-07T21:18:23","guid":{"rendered":"http:\/\/thelawlers.com\/Blognosticator\/?p=1861"},"modified":"2023-03-10T17:32:52","modified_gmt":"2023-03-11T01:32:52","slug":"more-in-my-grepping-drama","status":"publish","type":"post","link":"https:\/\/thelawlers.com\/Blognosticator\/?p=1861","title":{"rendered":"More in my GREPping drama"},"content":{"rendered":"<p><a href=\"https:\/\/thelawlers.com\/Blognosticator\/wp-content\/uploads\/2014\/07\/Blognosticator-Head.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1755\" src=\"https:\/\/thelawlers.com\/Blognosticator\/wp-content\/uploads\/2014\/07\/Blognosticator-Head.png\" alt=\"Blognosticator Head\" width=\"252\" height=\"115\" \/><\/a><\/p>\n<p>In past blogs I have expressed my love\u00a0for the GREP functions in InDesign. GREP is not only functional, but for me it\u2019s a lot of fun.<\/p>\n<p>I enjoy working with strings of text, manipulating things en masse to cause changes that would otherwise take too long.<\/p>\n<p>An example I have written about in the past is that of reversing names in a list from last name-first to first name-first. I have written a handful of GREP search instructions to do this, and none of them is completely perfect. That is still the case, but I discovered a couple of new GREP commands in InDesign that are very useful, and I want to share my success with you.<\/p>\n<p>The pattern of text that I work with is my class lists, which are sent to me by the university at the beginning of each quarter. These come with an overload of information, and I have to filter-out only the names to make a roll sheet for the first day of class.<\/p>\n<p>The patterns look like this:<\/p>\n<p><em>7 Bauer, Marcus Desmond mbauer09 GRC Freshman 3 Enrolled No<\/em><\/p>\n<p>The numeral is the number of the student in the list, then last name, first name, middle name (or not), e-mail address, the student\u2019s major, class level, the number after that is the units of the class, and then their enrollment status (always \u201cEnrolled\u201d) and whether the student has flagged his or her information to be kept private. When I look at the text, I look for <em>patterns<\/em> that I can search for:<\/p>\n<p><a href=\"https:\/\/thelawlers.com\/Blognosticator\/wp-content\/uploads\/2014\/11\/String-explanation.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1863\" src=\"https:\/\/thelawlers.com\/Blognosticator\/wp-content\/uploads\/2014\/11\/String-explanation.png\" alt=\"String explanation\" width=\"2025\" height=\"602\" srcset=\"https:\/\/thelawlers.com\/Blognosticator\/wp-content\/uploads\/2014\/11\/String-explanation.png 2025w, https:\/\/thelawlers.com\/Blognosticator\/wp-content\/uploads\/2014\/11\/String-explanation-300x89.png 300w, https:\/\/thelawlers.com\/Blognosticator\/wp-content\/uploads\/2014\/11\/String-explanation-1024x304.png 1024w\" sizes=\"auto, (max-width: 2025px) 100vw, 2025px\" \/><\/a><\/p>\n<p>I only need the second and third elements of all of this data, so GREP can help me accomplish this in two ways: 1, It strips off the unnecessary data, and 2, it reverses the last name and the first name.<\/p>\n<p>The implementation of GREP in InDesign is pretty good, but it varies slightly from the more \u201cpure\u201d GREP that is found in UNIX and in some text editing environments. But, that\u2019s OK with me, because InDesign is where I work most often with text, and it\u2019s very helpful to be able to use it there.<\/p>\n<p><a href=\"https:\/\/thelawlers.com\/Blognosticator\/wp-content\/uploads\/2014\/11\/GREP-Explanation.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1867\" src=\"https:\/\/thelawlers.com\/Blognosticator\/wp-content\/uploads\/2014\/11\/GREP-Explanation.png\" alt=\"GREP Explanation\" width=\"1288\" height=\"1389\" srcset=\"https:\/\/thelawlers.com\/Blognosticator\/wp-content\/uploads\/2014\/11\/GREP-Explanation.png 1288w, https:\/\/thelawlers.com\/Blognosticator\/wp-content\/uploads\/2014\/11\/GREP-Explanation-278x300.png 278w, https:\/\/thelawlers.com\/Blognosticator\/wp-content\/uploads\/2014\/11\/GREP-Explanation-949x1024.png 949w\" sizes=\"auto, (max-width: 1288px) 100vw, 1288px\" \/><\/a><\/p>\n<p><em><span style=\"color: #0000ff;\">This is the anatomy of my GREP search string in InDesign. It uses the commands that are new to me: the at-the-beginning-of-the-paragraph, and \u201cfind a word.\u201d<\/span><\/em><\/p>\n<p>The \u201cnew\u201d functions that I have discovered are the \u201cat the beginning of a paragraph\u201d command, which is a simple caret at the beginning of the command string, and the \u201cfind a word\u201d command, which I use twice in this search.<\/p>\n<p>\\w+ is the command to find a word. Words are defined as characters in any order, in any case, not separated by non-alphabetical characters (which you will see in my example here). Word does\u00a0find number strings<span style=\"color: #ff0000;\">*<\/span> and the underscore, but no other characters.<\/p>\n<p>So, to find the second and third data elements (both words), I search for (\\w+) twice, and I get both words.<\/p>\n<p>They\u2019re separated by a comma and a space in the text, so I put those characters in between, and that works also.<\/p>\n<p>To capture the numbers at the beginning of the paragraph (and no others), I use the command ^(\\d+ ) which finds any digit, one or more times, followed by a space. I put this inside of parentheses to pass it to a memory space called $1. Later I will not use that memory space, but I need to capture it for the short term.<\/p>\n<p>I then search for \u201ca word\u201d and pass those words to memory positions $2 and $3 for the last and first names, respectfully.<\/p>\n<p>After the student\u2019s names there is all that other information that I don\u2019t want. I use GREP\u2019s command for finding any character (this includes letters, numbers, figures \u2013 anything) followed by a standard carriage return. This gets rid of everything after the student\u2019s first name.<\/p>\n<p>Once I have all that, I put the first and last name back in the opposite order, and I\u2019m done.<\/p>\n<p><a href=\"https:\/\/thelawlers.com\/Blognosticator\/wp-content\/uploads\/2014\/11\/Replace-with.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1862\" src=\"https:\/\/thelawlers.com\/Blognosticator\/wp-content\/uploads\/2014\/11\/Replace-with.png\" alt=\"Replace with\" width=\"1335\" height=\"1012\" srcset=\"https:\/\/thelawlers.com\/Blognosticator\/wp-content\/uploads\/2014\/11\/Replace-with.png 1335w, https:\/\/thelawlers.com\/Blognosticator\/wp-content\/uploads\/2014\/11\/Replace-with-300x227.png 300w, https:\/\/thelawlers.com\/Blognosticator\/wp-content\/uploads\/2014\/11\/Replace-with-1024x776.png 1024w\" sizes=\"auto, (max-width: 1335px) 100vw, 1335px\" \/><\/a><\/p>\n<p><em><span style=\"color: #0000ff;\">This is the replace string for the search above. It\u2019s very simple: put the content of Memory 3 followed by the content of Memory 2 back on the line, separated by a space, and followed by a standard carriage return. The comma after the last name is automatically dropped because it was not inside the parentheses in the search string.<\/span><\/em><\/p>\n<p>In my earlier method for this, my search criteria usually failed when a capital letter showed up in a name, like DuPont. This new method works for those kind of names. But, it doesn\u2019t work for names that have spaces in them, nor for words with hyphens.<\/p>\n<p>In the past I had to fix those names by hand, and I still have to do that, but with fewer names now.<\/p>\n<p><a href=\"https:\/\/thelawlers.com\/Blognosticator\/wp-content\/uploads\/2014\/11\/Class-list.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1865\" src=\"https:\/\/thelawlers.com\/Blognosticator\/wp-content\/uploads\/2014\/11\/Class-list.png\" alt=\"Class list\" width=\"533\" height=\"587\" srcset=\"https:\/\/thelawlers.com\/Blognosticator\/wp-content\/uploads\/2014\/11\/Class-list.png 533w, https:\/\/thelawlers.com\/Blognosticator\/wp-content\/uploads\/2014\/11\/Class-list-272x300.png 272w\" sizes=\"auto, (max-width: 533px) 100vw, 533px\" \/><\/a><\/p>\n<p><em><span style=\"color: #0000ff;\">This is the list as I receive it from the university.<\/span><\/em><\/p>\n<p><a href=\"https:\/\/thelawlers.com\/Blognosticator\/wp-content\/uploads\/2014\/11\/Class-list-with-highlights.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1866\" src=\"https:\/\/thelawlers.com\/Blognosticator\/wp-content\/uploads\/2014\/11\/Class-list-with-highlights.png\" alt=\"Class list with highlights\" width=\"533\" height=\"453\" srcset=\"https:\/\/thelawlers.com\/Blognosticator\/wp-content\/uploads\/2014\/11\/Class-list-with-highlights.png 533w, https:\/\/thelawlers.com\/Blognosticator\/wp-content\/uploads\/2014\/11\/Class-list-with-highlights-300x254.png 300w\" sizes=\"auto, (max-width: 533px) 100vw, 533px\" \/><\/a><\/p>\n<p><em><span style=\"color: #0000ff;\">\u2026and this is the same list with potential problems highlighted in red. In my previous GREPping dramas, I have had to fix all of the lines marked in red.<\/span><\/em><\/p>\n<p>By using the new search criteria, I can fix most of these, but not all:<\/p>\n<p><a href=\"https:\/\/thelawlers.com\/Blognosticator\/wp-content\/uploads\/2014\/11\/Names-after-GREP.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1864\" src=\"https:\/\/thelawlers.com\/Blognosticator\/wp-content\/uploads\/2014\/11\/Names-after-GREP.png\" alt=\"Names after GREP\" width=\"533\" height=\"444\" srcset=\"https:\/\/thelawlers.com\/Blognosticator\/wp-content\/uploads\/2014\/11\/Names-after-GREP.png 533w, https:\/\/thelawlers.com\/Blognosticator\/wp-content\/uploads\/2014\/11\/Names-after-GREP-300x249.png 300w\" sizes=\"auto, (max-width: 533px) 100vw, 533px\" \/><\/a><\/p>\n<p><em><span style=\"color: #0000ff;\">Notice that only two of the four potential problems were not processed correctly: those with spaces in the last name, and one with a hyphenated last name.<\/span><\/em><\/p>\n<p>It\u2019s easy to fix those that are not processed by the search string, and it only takes a few seconds.<\/p>\n<p><span style=\"color: #ff0000;\">* An addendum (November 9, 2014):<\/span>\u00a0Though it doesn\u2019t make any difference in performance, it is possible to search for three \u201cwords\u201d \u2013 the first being the serial number, the second being the student\u2019s last name, and the third being his or her first name. The search string looks like this:<\/p>\n<p><span style=\"color: #ff0000;\">^(\\w+) (\\w+), (\\w+) (.+~b)<\/span><\/p>\n<p>The result is identical.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In past blogs I have expressed my love\u00a0for the GREP functions in InDesign. GREP is not only functional, but for me it\u2019s a lot of fun. I enjoy working with strings of text, manipulating things en masse to cause changes &hellip; <a href=\"https:\/\/thelawlers.com\/Blognosticator\/?p=1861\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24,26],"tags":[64,444,330,446,447,445],"class_list":["post-1861","post","type-post","status-publish","format-standard","hentry","category-printing-and-printing-processes","category-typography-2","tag-brian-lawler","tag-grep","tag-grep-in-indesign","tag-indesign-find-and-change","tag-indesign-typograpy","tag-pattern-searching-in-indesign"],"_links":{"self":[{"href":"https:\/\/thelawlers.com\/Blognosticator\/index.php?rest_route=\/wp\/v2\/posts\/1861","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thelawlers.com\/Blognosticator\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thelawlers.com\/Blognosticator\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thelawlers.com\/Blognosticator\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/thelawlers.com\/Blognosticator\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1861"}],"version-history":[{"count":4,"href":"https:\/\/thelawlers.com\/Blognosticator\/index.php?rest_route=\/wp\/v2\/posts\/1861\/revisions"}],"predecessor-version":[{"id":3581,"href":"https:\/\/thelawlers.com\/Blognosticator\/index.php?rest_route=\/wp\/v2\/posts\/1861\/revisions\/3581"}],"wp:attachment":[{"href":"https:\/\/thelawlers.com\/Blognosticator\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1861"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thelawlers.com\/Blognosticator\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1861"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thelawlers.com\/Blognosticator\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1861"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}