<?xml version="1.0" encoding="UTF-8"?><div xmlns="http://www.tei-c.org/ns/1.0" xml:id="learn_regexPreFormed" resp="or:odd_JENS1_wtm or:odd_ELHA1_wtm or:odd_VATC1_wtm or:odd_HOUL3_wtm or:odd_GALL2_wtm or:odd_SEAL1_pfr or:odd_GALL2_pfr" ana="audRemediator"><!-- JENS1 wrote the explanations; ELHA1 and HOUL3 wrote the regular expressions; VATC1 added them to this file. JENS1 and HOUL3 added regular expressions on an ongoing basis. -->
   <head>Pre-Formed Regular Expressions</head>
    
    
    <div xml:id="learn_regexPreFormed_prior">
        <head>Prior Reading</head>
        
        <list rend="bulleted">
            <item><ptr target="doc:learn_regex"/></item>
        </list>
    </div>
    
    
    <div xml:id="learn_regexPreFormed_allEditionComponents">
        <head>Regex for All Edition Components</head>
        
        <p>The regular expressions in this section are useful in multiple edition components (e.g., you may use them in annotations and critical paratexts).</p>
        
        <table>
            <row role="label">
                <cell>Rationale</cell>
                <cell>Find</cell>
                <cell>Replace With</cell>
            </row>
            <row role="data" xml:id="learn_regexPreFormed_replaceQ">
                <cell>Replaces quotation marks with <gi>q</gi> in converted files.</cell>
                <cell>
                   <code>"([\w][^"]+)"(([\W])|($))</code> (Note: constrain to <code>text()</code> in the XPath context)
                </cell>
                <cell>
                   <code>&lt;q&gt;$1&lt;/q&gt;$2</code>
                </cell>
            </row>
           <row role="data" xml:id="learn_regexPreFormed_replaceHyphen">
                <cell>LEMDO uses en dashes in date and number ranges. We frequently receive files from editors that contain hyphens. This converts such hyphens to en dashes (without converting the hyphens that occur in the dates that are the values of attributes).</cell>
                <cell>
                   <code>(\d+)-(\d+)</code> (Note: constrain to <code>text()</code> in the XPath context)
                </cell>
                <cell>
                   <code>$1–$2</code>
                </cell>
            </row>
        </table>
    </div>
    
    
    <div xml:id="learn_regexPreFormed_semiDip">
        <head>Regex for Semi-Diplomatic Transcriptions</head>
        
        <p>The regular expressions in this section are used in semi-diplomatic transcriptions that were converted from IML.</p>
        
        <table>
            <row role="label">
                <cell>Rationale</cell>
                <cell>Find</cell>
                <cell>Replace With</cell>
            </row>
           <row role="data" xml:id="learn_regexPreFormed_removeExtraLb">
                <cell>When you are working with IML-TEI converted texts, you may come across a lot of situations where an <gi>lb</gi> element appears right inside the <gi>ab</gi> of a speech, instead of before the <gi>sp</gi> tag. This removes those unwanted <gi>lb</gi> elements. Note: we recommend running this regex before adding renditions or making other changes to the file.</cell>
               <cell>
                  <code>(&lt;sp&gt;\s+&lt;speaker&gt;.+?&lt;/speaker&gt;\s*&lt;ab&gt;\s*)(&lt;lb/&gt;)</code> (Note: make sure you check <quote>Dot matches all</quote>)
               </cell>
               <cell>
                  <code>$2$1</code>
               </cell>
            </row>
           <row role="data" xml:id="learn_regexPreFormed_removeEditorialLineNumber">
                <cell>This removes <gi>lb</gi> elements with <att>n</att> giving editorial line numbers.</cell>
                <cell>
                   <code>&lt;lb\s+n="\d*\.*\d*"/&gt;</code>
                </cell>
                <cell>Leave empty</cell>
            </row>
           <row role="data" xml:id="learn_regexPreFormed_removeOldFacs">
                <cell>When you convert a file from TCP or IML to TEI, there will likely be old facsimile links in the <gi>pb</gi> element. This removes old facsimile links.</cell>
                <cell>
                   <code>(&lt;pb)\sfacs=".+?"(/&gt;)</code>
                </cell>
                <cell>
                   <code>$1$2</code>
                </cell>
            </row>
           <row role="data" xml:id="learn_regexPreFormed_correctElementOrderSemiDip">
                <cell>You may come across instances of the <gi>lb</gi> element appearing after <gi>sp</gi> rather than before it. This corrects order of elements.</cell>
               <cell>
                 <code>(&lt;sp&gt;\s+)(&lt;lb/&gt;\s*)(&lt;speaker&gt;.+?&lt;/speaker&gt;)</code>
               </cell>
               <cell>
                  <code>$2$1$3</code>
               </cell>
            </row>
           <row role="data" xml:id="learn_regexPreFormed_standardizeAttributeOrderFW">
               <cell>Standardizes attribute order on forme works. Note: this regex should be run before running any other regex on forme works.</cell>
               <cell>
                  <code>&lt;fw(\srendition="(\s*\w+:\w+)+")(\stype="\w+")</code>
                  <note type="editorial">Explanation of find regex: this regex has three backreference groups:
                     <list rend="numbered">
                        <item><code>(\srendition="(\s*\w+:\w+)+")</code>: contains the <att>rendition</att> attribute and its value(s)</item>
                        <item><code>(\s*\w+:\w+)+</code>: accounts for one or more values on the <att>rendition</att> attribute (note that format for <att>rendition</att> values is <val>rnd:[value]</val>)</item>
                        <item><code>(\stype="\w+")</code>: contains the <att>type</att> attribute and its value</item>
                     </list>
                  </note>
               </cell>
               <cell>
                  <code>&lt;fw$3$1</code>
                  <note type="editorial">Explanation of replace regex: by putting $3 before $1 in the replace, this regex places the <att>type</att> attribute before the <att>rendition</att> attribute, which will format the <gi>fw</gi> elements correctly for other regex.</note></cell>
            </row>
           <row role="data" xml:id="learn_regexPreFormed_removeCentreSig">
                <cell>LEMDO’s default styling is to centre signature numbers. This removes unnecessary <att>rendition</att> attributes that only have the value <val>rnd:centre</val> from signature numbers.</cell>
                <cell>
                   <code>(&lt;fw type="sig")\srendition="rnd:centre"</code>
                </cell>
                <cell>
                   <code>$1</code>
                </cell>
            </row>
           <row role="data" xml:id="learn_regexPreFormed_removeRightCatch">
               <cell>LEMDO’s default styling is to align catch words to the right. This removes unnecessary <att>rendition</att> attributes that only have the value <val>rnd:right</val> from catch words.</cell>
               <cell>
                  <code>(&lt;fw type="catch")\srendition="rnd:right"</code>
               </cell>
               <cell>
                  <code>$1</code>
               </cell>
            </row>
           <row role="data" xml:id="learn_regexPreFormed_removeSigSpace">
              <cell>Removes unnecessary space from between the letter and number of signature marks</cell>
              <cell>
                 <code>(&lt;fw type="sig"&gt;[a-zA-Z]+)\s(\d&lt;/fw&gt;)</code>
                 <note type="editorial">Explanation of find regex: this find has two backreference groups that are kept in the conversion:
                    <list rend="numbered">
                       <item><code>(&lt;fw type="sig"&gt;[a-zA-Z]+)</code>: contains the opening <gi>fw</gi> tag, all of the attributes on it, and the letter of the signature mark.</item>
                       <item><code>(\d&lt;/fw&gt;)</code>: contains the number of the signature mark and the closing <tag>/fw</tag> tag.</item>
                    </list>
                    <list rend="bulleted">
                       <item><code>&lt;fw type="sig"&gt; … &lt;/fw&gt;</code>: constrains the search to text encoded as signature marks.</item>
                       <item><code>[a-zA-Z]+</code>: indicates the letter or letters in the signature mark. They may be capital or lower case letters, and there will be at least one (there may be more than one in long books with lots of gatherings).</item>
                       <item><code>\s</code>: indicates the space between the letter and number. This will be removed in the conversion.</item>
                       <item><code>\d</code>: indicates the number in the signature mark.</item>
                    </list>
                 </note>
              </cell>
              <cell>
                 <code>$1$2</code>
                 <note type="editorial">Explanation of replace regex:
                    <list rend="bulleted">
                       <item><code>$1</code>: Keeps the first backreference group during the conversion process.</item>
                       <item><code>$2</code>: Keeps the second backreference group during the conversion process.</item>
                    </list>
                    By excluding the <code>\s</code> from the replace, we eliminate the unwanted space.
                 </note>
              </cell>
           </row>
           <row role="data" xml:id="learn_regexPreFormed_removeItalicCentreRunningTitle">
              <cell>Removes italic and centre tagging from running titles. Note: after running this, always also run the <ref target="#learn_regexPreFormed_removeEmptyRendition">regex to remove empty <att>rendition</att> attributes</ref>.</cell>
              <cell>
                 <code>(&lt;fw\stype="runningTitle"\srendition=")((\s*rnd:centre)|(\s*rnd:italic)|(\s*(rnd:\w+)))*"</code>
              </cell>
              <cell>
                 <code>$1$6"</code>
              </cell>
           </row>
           <row role="data" xml:id="learn_regexPreFormed_removeEmptyRendition">
              <cell>Removes empty <att>rendition</att> attributes. Note: run this after using regex to remove values from <att>rendition</att> attributes.</cell>
              <cell>
                 <code>\srendition=""</code>
              </cell>
              <cell>Leave empty</cell>
           </row>
           <row role="data" xml:id="learn_regexPreFormed_removeItalicCentreHiOnRendition">
              <cell>Removes italic and centre tagging on <gi>hi</gi> elements in running titles. Note: after running this, always also run the <ref target="#learn_regexPreFormed_removeEmptyHi">regex to remove empty <gi>hi</gi> elements</ref>.</cell>
              <cell>
                 <code>(&lt;hi\srendition=")((\s*rnd:centre)|(\s*rnd:italic)|(\s*(rnd:\w+)))*"</code>
                 (Note: constrain to <code>//fw[contains(@type, 'runningTitle')]</code> in the XPath field)
              </cell>
              <cell>
                 <code>$1$6</code>
              </cell>
           </row>
           <row role="data" xml:id="learn_regexPreFormed_removeEmptyHi">
              <cell>Removes empty <gi>hi</gi> elements after getting rid of values. Note: run this after using regex to remove values from <att>rendition</att> attributes on the <gi>hi</gi> element.</cell>
              <cell>
                 <code>&lt;hi\srendition=""&gt;(.+?)&lt;\hi&gt;</code>
              </cell>
              <cell>
                 <code>$1</code>
              </cell>
           </row>
           <row role="data" xml:id="learn_regexPreFormed_removeItalicSpeaker">
              <cell>Removes italic tagging on <gi>speaker</gi> elements. Note: after running this, always also run the <ref target="#learn_regexPreFormed_removeEmptyRendition">regex to remove empty <att>rendition</att> attributes</ref>.</cell>
              <cell>
                 <code>(&lt;speaker\srendition=")((\s*rnd:italic)|(\s*(\w+:\w+)))*"</code>
              </cell>
              <cell>
                 <code>$1$5"</code>
              </cell>
           </row>
           <row role="data" xml:id="learn_regexPreFormed_removeItalicAddNormalHiInSpeechPrefix">
              <cell>Removes italic tagging on <gi>hi</gi> elements in speech prefixes and adds <gi>hi</gi> elements with <val>rnd:normal</val> around characters in roman type. Note: after running this, always also run the <ref target="#learn_regexPreFormed_removeEmptyHi">regex to remove empty <gi>hi</gi> elements</ref> and the <ref target="#learn_regexPreFormed_removeHiEmptyTextNode">regex to remove <gi>hi</gi> elements with empty text nodes</ref>.</cell>
              <cell>
                 <code>(&lt;speaker&gt;)(.+?)*(&lt;hi\srendition=")((\s*rnd:italic)|(\s*(\w+:\w+)))*"&gt;(.+?)*(&lt;/speaker&gt;)</code>
              </cell>
              <cell>
                 <code>$1&lt;hi rendition="rnd:normal"&gt;$2&lt;/hi&gt;$3&lt;hi rendition="rnd:normal"&gt;$4&lt;/hi&gt;$5</code>
              </cell>
           </row>
           <row role="data" xml:id="learn_regexPreFormed_removeHiEmptyTextNode">
              <cell>Removes <gi>hi</gi> element with empty text nodes.</cell>
              <cell><code>&lt;hi\srendition=".+?"&gt;&lt;/hi&gt;</code></cell>
              <cell>Leave empty</cell>
           </row>
           <row role="data" xml:id="learn_regexPreFormed_standardizeAttributesStage">
              <cell>Standardizes the order of attributes on the <gi>stage</gi> element. Note: run this regex before running any other regex on stage directions.</cell>
              <cell>
                 <code>(&lt;stage)(\srendition="(\s*(\w+:\w+))+")(\stype="(\s*\w+)+")</code>
              </cell>
              <cell>
                 <code>$1$5$2</code>
              </cell>
           </row>
           <row role="data" xml:id="learn_regexPreFormed_removeItalicStage">
              <cell>Removes italic tagging on <gi>stage</gi> elements. Note: after running this, always also run the <ref target="#learn_regexPreFormed_removeEmptyRendition">regex to remove empty <att>rendition</att> attributes</ref>.</cell>
              <cell>
                 <code>(&lt;hi\srendition=")((\s*rnd:italic)|(\s*(rnd:\w+)))*"</code>
                 (Note: constrain to <code>//stage</code> in the XPath field)
              </cell>
              <cell>
                 <code>$1$5</code>
              </cell>
           </row>
           <row role="data" xml:id="learn_regexPreFormed_removeItalicHiInStage">
              <cell>Removes italic tagging using the <gi>hi</gi> element in stage directions. Note: after running this, always also run the <ref target="#learn_regexPreFormed_removeEmptyHi">regex to remove empty <gi>hi</gi> elements</ref>.</cell>
              <cell>
                 <code>(&lt;hi\srendition=")((\s*rnd:italic)|(\s*(rnd:\w+)))*"</code>
                 (Note: constrain to <code>//stage</code> in the XPath field)
              </cell>
              <cell>
                 <code>$1$5"</code>
              </cell>
           </row>
           <row role="data" xml:id="learn_regexPreFormed_removeWho">
              <cell>Removes <att>who</att> attributes</cell>
              <cell><code>&lt;sp who="#\w+"&gt;</code><note type="editorial">Explanation of find regex:
                 <list rend="bulleted">
                    <item><code>&lt;sp&gt;</code>: Constrains the search to <gi>sp</gi> elements.</item>
                    <item><code>who="#\w+"</code>: Searches for the <att>who</att> attribute. This is the section that will be removed during the conversion. The hash character indicates that every value for the <att>who</att> attribute is prefixed by a hash character. <code>\w</code> indicates that the value following the hash character may consist of alphanumeric characters and underscores (word characters). The plus sign indicates that there will be one or more word character.</item>
                 </list>
              </note></cell>
              <cell><code>&lt;sp&gt;</code></cell>
           </row>
           <row role="data" xml:id="learn_regexPreFormed_removeJustify">
              <cell>Removes <val>rnd:justify</val>. Note: after running this, always also run the <ref target="#learn_regexPreFormed_removeEmptyHi">regex to remove empty <gi>hi</gi> elements</ref>.</cell>
              <cell><code>\srendition="rnd:justify"</code></cell>
              <cell>Leave empty</cell>
           </row>
           <row role="data" xml:id="learn_regexPreFormed_removeSuppliedPage">
              <cell>Removes supplied page numbers on the <att>n</att> attribute on the <gi>pb</gi> element</cell>
              <cell><code>(&lt;pb\sn=")\d+;\s(\w+"/&gt;)</code></cell>
              <cell><code>$1$2</code></cell>
           </row>
           <row role="data" xml:id="learn_regexPreFormed_standardizeAttributeOrderLb">
              <cell>The XSLT conversion to programmatically number lines in semi-diplomatic transcriptions puts the <att>n</att> attribute before the <att>type</att> attribute. While this is valid XML, LEMDO opts for the <att>type</att> attribute to appear before the <att>n</att> attribute. Consistency ensures easy searchability across our repository. This regex reorders the attributes so that they are consistent.</cell>
              <cell><code>(&lt;lb)(\sn="\d+")(\stype="wln")(/&gt;)</code></cell>
              <cell><code>$1$3$2$4</code></cell>
           </row>
        </table>
    </div>
   
   
   <div xml:id="learn_regexPreFormed_modern">
      <head>Regex for Modernized Texts</head>
      
      <p>The regular expressions in this section are used in modernized texts that were converted from IML.</p>
      
      <table>
         <row role="label">
            <cell>Rationale</cell>
            <cell>Find</cell>
            <cell>Replace With</cell>
         </row>
         <row role="data" xml:id="learn_regexPreFormed_addDivN">
            <cell>Adds <att>n</att> attribute to <gi>div</gi> elements</cell>
            <cell><code>&lt;div type="(\w+)" xml:id="([a-zA-Z]+_\w*)_([a-z])(\d+)"&gt;</code></cell>
            <cell><code>&lt;div type="$1" n="$4" xml:id="$2_$3$4"&gt;</code></cell>
         </row>
      </table>
   </div>
   
   
   <div xml:id="learn_regexPreFormed_otherResources">
      <head>Other Resources</head>
      
      <list rend="bulleted">
         <item>LEMDO YouTube video: <ref target="https://youtu.be/ncqs5oV25WE">Modernization (Technical): Regular Expressions</ref></item>
         <item>Jan Goyvaerts’s <ref target="https://www.regular-expressions.info/">Regular-Expressions.info</ref></item>
      </list>
   </div>
</div>