title: Regex for multiple occurrences of specific words
body: <p>Hello</p>
  
  <p>I'm trying to create a validation rule that checks the regular expression to accept only specific phrases. Regex is based on Java.</p>
  
  <p>Here are examples of correct inputs:
    <li><code>1OR2</code></li>
     <li> <code>2</code></li>
     <li> <code>1 OR 2 OR 15</code></li>
      <li><code>(  2OR3) AND 1</code></li>
      <li><code>(12AND13 AND1)OR(4   AND5)</code></li>
     <li><code>((2AND3 AND 1)OR(4AND5))AND6</code></li>
  but I would be happy if only the regex could accept anything like :</p>
  
  <p><code>())34AND(4</code></p>
  
  <p>I have no idea how to create a regex to check if the brackets open and close correctly(they can be nested). I assumed it can be impossible to check it in regex so the proper validation for the brackets I've already made in the code(stack implementation). In the code I have a second step validation of the phrase.</p>
  
  <p>All I need the regex to do is to check if there are these specific things inside the phrase:</p>
  
  <p>numbers, round brackets, words AND and OR with multiple occurrences and whitespaces are allowed.
  It should NOT accept letters or other characters.
  All I managed to create so far is this:</p>
  
  <p><code>^[0-9 \\(][0-9 \\(\\)]*</code></p>
  
  <p>also tried adding something like: </p>
  
  <p><code>\\b(AND|OR)\\b</code></p>
  
  <p>inside the second pair of brackets but with no luck.</p>
  
  <p>I cannot figure out how to correct it to add OR and AND words.</p>