title: How do make a regular expression to match file paths?
body: <p>I've been playing with this command for about an hour or two and I'm afraid I may have lost objectivity. <strong>The goal is to match only relative file paths given to bash.</strong></p>
  
  <p>The first relative path <code>.</code> or <code>./some/file/path</code></p>
  
  <p>The second relative path is <code>..</code> or <code>../some/file/path</code></p>
  
  <p>Where the length of "/some/file/path" is arbitrary.</p>
  
  <p>I've been using <code>grep</code> within <code>bash</code> to try and figure out how to implement it in to my script so that I can expand it to it's absolute file path so that <code>./some/file/path</code> or <code>../some/file/path</code> becomes <code>/the/absolute/file/path</code>; which I've already figure out. </p>
  
  <p><strong>My problem is matching the relative path.</strong></p>
  
  <p>The code I've been using is</p>
  
  <pre><code>echo "../some/file/path" | egrep '\.{1}/?[[:graph:]]?+$'
  </code></pre>
  
  <p>and</p>
  
  <pre><code>echo "../some/file/path" | egrep '\.{2}/?[[:graph:]]?+$'
  </code></pre>
  
  <p>and I've narrowed my issue down to being</p>
  
  <pre><code>echo ".." | egrep '\.{2}'
  </code></pre>
  
  <p>will match the dot as long as it has <code>2 + n</code> occurrences, <strong>not exactly 2 occurrences</strong> as expected. The same thing happens when I change it to </p>
  
  <pre><code>echo ".." | egrep '\.{1}' 
  </code></pre>
  
  <p>will still match for some reason I can't figure out.</p>
  
  <p>The final implementation is supposed to work something like this</p>
  
  <pre><code> 41 _expand_relative_path () {
   42         if [[ "$1" =~ ^\.{1}/?[[:graph:]]?+$ ]]; then
   43                 echo "."
   44         elif [[ "$1" =~ ^\.{2}/?[[:graph:]]?+$ ]]; then
   45                 echo ".."
   46         else    
   47                 echo "$1"
   48         fi
   49 }
  </code></pre>
  
  <p>According to my text book, the specifier {n} will match the preceding element if it occurs exactly n times. But it doesn't do that! It matches if it is n or more times! What am I doing wrong?</p>