title: How to match 2 out of 3 groups with a non-password-related regular expression in Python?
body: <p>I've looked at <a href="https://stackoverflow.com/questions/5950756/regex-for-checking-that-at-least-3-of-4-different-character-groups-exist">this answer</a> and <a href="https://stackoverflow.com/questions/22204836/regex-to-find-3-out-of-4-conditions">this answer</a> to try to figure out my problem, but I'm not sure they're directly applicable because a) I don't have a condition that always has to be met, and b) the document is so messy that allowing for any of the three to match would result in a large amount of false positives.</p>
  
  <p>So, with that being said, here is my issue. I have lines of text that I want to match that look like this:<br>
  <code>x = "10/04             Some brief description blah blah   blah     45.00"</code></p>
  
  <p>where the spacing between everything is messy. Then, I have some lines of text that I want to match that look like this:<br>
  <code>y = "VJ../VI           Another stupid brief description    1000.00"</code><br>
  <code>z = "11/13         This is another description   LO05.13"</code></p>
  
  <p>The regular expression I'm currently using is this:<br>
  <code>regex = r"^(\d\d\s?[1/]\s?\d\d\s?[1/]\d\d)\s+(\S+(?:\s+\S+)*?)\s+(-?\s?[\d,]+\.\d\d)"</code></p>
  
  <p>The problem is that in <code>y</code> <code>regex</code> doesn't match because there is no date at the beginning of the string; the OCR process messed up. However, we still know that it's a valid line because it has a description and an amount. <code>regex</code> won't match <code>z</code> either because the amount is not a bunch of digits, but we know it's a transaction because there's a date and a description.</p>
  
  <p>I've considered changing the regex to look like this:<br>
  <code>regex = r"^(\d\d\s?[1/]\s?\d\d\s?[1/]\d\d\s+)?(\S+(?:\s+\S+)*?)\s+(-?\s?[\d,]+\.\d\d)?"</code></p>
  
  <p>But I'm worried that that will just match everything in the document (i.e. "Withdrawals and Debits"). And since the two optional pieces of the line of text are on opposite ends of the more consistent piece of the text, I'm not sure how to implement <code>|</code> like in the solutions to the questions I linked.</p>
  
  <p>Is my best option to just make two different regular expressions, linked with <code>|</code>, like so?<br>
  <code>regex = r"^(\d\d\s?[1/]\s?\d\d\s?[1/]\d\d\s+)?(\S+(?:\s+\S+)*?)\s+(-?\s?[\d,]+\.\d\d)|^(\d\d\s?[1/]\s?\d\d\s?[1/]\d\d)\s+(\S+(?:\s+\S+)*?)\s+(-?\s?[\d,]+\.\d\d)?"</code></p>
  
  <p>Any assistance would be appreciated. Thanks</p>