title: Texts in some cells update but not all cells using runs with python-docx
body: <p>I'm trying to update the dates on an existing docx file. The file has one table with 3 columns and 25 rows. Each cell starts with a date in this format <code>Aug. 17-18, 2021</code>. My goal is to go through every cell and change the date to this year's, so that date should become Aug. 16-17, 2022.</p>
  <p>Code:</p>
  <pre><code>from docx import Document
  
  doc = Document(&quot;AP2021.docx&quot;)
  table = doc.tables[0]
  
  int_dates = []
  ones = []
  for i in range(10, 32):
      int_dates.append(i)
  
  for i in range(2, 10):
      ones.append(i)
  
  dates = [str(x) for x in int_dates]
  ones_dates = [str(x) for x in ones]
  
  for row in table.rows:
      for cell in row.cells:
          for date in dates:
              # Update 10's and 20's of date
              if date in cell.paragraphs[0].text:
                  new_date = str(int(date) - 1)
                  run = cell.paragraphs[0].runs
                  for i in range(len(run)):
                      if date in run[i].text:
                          run[i].text = run[i].text.replace(date, new_date)
  
              else:
                  # Update ones of date separately because other text in cell uses the same numbers
                  for one in ones_dates:
                      if one in cell.paragraphs[0].text:
                          new_one = str(int(one) - 1)
                          run = cell.paragraphs[0].runs
                          for i in range(len(run)):
                              if one in run[i].text:
                                  run[i].text = run[i].text.replace(one, new_one)
                              elif '1' in run[i].text:
                                  run[i].text = run[i].text.replace('1', '31')
                              break;
                      break;
                     
          # one and two were used to check if 1920 and 1010 were detected. More two's were printed than one's. 
          if '1920' or '1010' in cell.text:
              print(&quot;one&quot;)
              run = cell.paragraphs[0].runs
              for i in range(len(run)):
                  if '1920' or '1010' in run[i].text:
                      print(&quot;two&quot;)
                      run[i].text = run[i].text.replace('1920' or '1010', '2022')
  
  
  doc.save(&quot;AP2022.docx&quot;)
  </code></pre>
  <p>Originally, I was able to change the dates using paragraphs.text but that removed all the formatting (highlight, bold, comments, etc.) for the cell. Following a comment on one of the posts, I replaced .text with .runs. The format was kept but for some reason, some cells' dates were updated but with incorrect year, some had updated year but not the correct date, some had correct date and year, and some had incorrect date and year.</p>
  <p>I tried putting the year update code within the for loop for updating the date, but that didn't help. One of the posts said that .runs is inconsistent and hard to tell what part of the paragraph is actually wrapped for editing. All the runs examples I found were used with adding new text which wasn't what I wanted.</p>
  <p>Is there a way for all the dates to be changed? Thank you.</p>