title: Multiline Bash Regex Match
body: <p>I've been reading through tons of threads about this, but none have helped me yet.</p>
  
  <p>This is a sample of my text:</p>
  
  <pre><code>    [userId:@"1"
          userName:@""
              userPos:@[@"11006321C", ]
           userDisp:@[@"4200012FD6", ]];
  
  
  
  [userId:@"2"
          userName:@""
              userPos:@[@"412520084C",
                       @"7200851", 
                       @"54720021", 
                       ]
          userDisp:@[@"230035FD6", 
                       @"3213456432C0035FD6", 
                       @"1F200538D5", 
                       ]];
  </code></pre>
  
  <p>I'm trying to capture this:</p>
  
  <pre><code>userPos:@[@"11006321C", ]
           userDisp:@[@"4200012FD6", ]]
  </code></pre>
  
  <p>and</p>
  
  <pre><code>userPos:@[@"412520084C",
                       @"7200851", 
                       @"54720021", 
                       ]
          userDisp:@[@"230035FD6", 
                       @"3213456432C0035FD6", 
                       @"1F200538D5", 
                       ]]
  </code></pre>
  
  <p>(All matches from the text) using regex: <code>userPos:@\[((?:.\r?\n?)*)\]</code></p>
  
  <p>Trying it in bash using:</p>
  
  <pre><code>for string in $file # text has been read into this variable
  do
      [[ $word =~ $regex ]]
      if [[ ${BASH_REMATCH[0]} ]]
      then
          string="${x:+x }${BASH_REMATCH[0]}"
          userlist+=("$string")
          echo "$string"
      fi
  done
  </code></pre>
  
  <p>To append them to a list.</p>
  
  <p>But this doesn't work since the regex matches noting at all. I know there are different kinds of Regex engines and stuff, and I've tried so many different regexes for this to work in bash, but can't seem to get it to work.</p>
  
  <p>Anyone who could help me capture what I want in bash?</p>