title: How to use a regex with Awk to extract the substring between parentheses?
body: <p>In the following Bash command line, I am able to obtain the index for the substring, when the substring is between double quotes.</p>
  
  <pre><code>text='123ABCabc((XYZabc((((((abc123(((123'
  
  echo $text | awk '{ print index($0, "((((a" )}'  # 20 is the result.
  </code></pre>
  
  <p>However, in my application, I will not know what character will be where the "a" is in this example. Therefore, I thought I could replace the "a" with a regex that accepted any character other than "(". I thought that /[^(}/ would be what I needed. However, I have been unable to get the Awk index command to work with any form of regex in place of the "((((a" in the example.</p>
  
  <p><strong>UPDATE:</strong> It was pointed out by William Pursell that the index operation does not accept a regex as the second operand.</p>
  
  <p>Ultimately, what I was trying to accomplish was to extract the substring that was located after four or more "(", followed by one or more ")".  Dennis Williamson provided the solution with the following code:</p>
  
  <pre><code>echo 'dksjfkdj(((((((I-WANT-THIS-SUBSTRING)askdjflsdjf' | 
  mawk '{match($0,/\(\(\(\([^()]*\)/); s = substr($0,RSTART, RLENGTH); gsub(/[()]/, "", s); print s}'
  </code></pre>
  
  <p>Thanks to all for their help!</p>