title: regex match bash variable
body: <p>I am trying to modify a bash script.  The script current contains</p>
  
  <pre><code>print "&lt;div class=\"title\"&gt;" $1 "&lt;/div&gt;"
  </code></pre>
  
  <p>Where <code>$1</code> may look like:</p>
  
  <pre><code>Apprentice Historian (Level 1)
  Historian (Level 4)
  Master Historian (Level 7)
  </code></pre>
  
  <p>What i'd like to do is add an image which is named the "base" value.  I had something like this in mind:</p>
  
  <pre><code>print "&lt;div class=\"icon\"&gt;&lt;imgsrc=\"icons\" $1 ".png\"&gt;&lt;/div&gt;&lt;div class=\"title\"&gt;" $1 "&lt;/div&gt;"
  </code></pre>
  
  <p>However, in this case I'd like <code>$1</code> to only return <code>Historian</code>. I was thinking I could use a regex to match and on <code>$1</code> and keep only the part I need.</p>
  
  <pre><code>(Apprentice|Master)?\s(.*)\s(\(Level \d\)) 
  </code></pre>
  
  <p>I know my regex isn't quite there, ideally apprentice/master would be in their own match group and not tied the base.  And I don't know how to match on the <code>$1</code> argument.</p>