title: Ruby or Bash or Grep regex is not working for '?' i.e. 0 or 1 occurrence of previous character
body: <p><strong>Linux</strong> Red Hat Enterprise Linux Server release 6.9 (Santiago)</p>
  
  <p><strong>Issue:</strong><br/>
  I have 2 Jenkins jobs and they both which calls another common/reusable downstream job (that uses a regex to pick its rpm). Actual code is written in Ruby (where I was using <code>::Dir.glob("&lt;pattern&gt;",'')</code> and it didn't work for picking the correct rpm name (without giving me any error), but here I'm just focusing on the regex part.</p>
  
  <p>In <strong>job1</strong>, in my workspace, I see <code>myrpm.rpm</code> and <code>myrpm-extra.rpm</code>.</p>
  
  <p>In <strong>job2</strong>, in my workspace, I see <code>myrpm-3.0.0.1027-2018_12_21_121519.noarch.rpm</code> and <code>myrpm-extra-3.0.0.1027-2018_12_21_121519.noarch.rpm</code> rpms which I'm getting after downloading these files from Artifactory via some AQL.</p>
  
  <p>Once rpms are downloaded from Aritfactory i.e. available in Jenkins workspace , then I use this common downstream job to pick a given rpm that I need by
  using <code>"${rpmname}*.rpm"</code> regex. </p>
  
  <p>The issue is, when I'm passing <code>rpmname</code> parameter value as "<strong>myrpm</strong>", the logic is picking <code>myrpm-extra.rpm</code> (in <strong><em>Job1</em></strong>) or <code>myrpm-extra-3.0.0.1027-2018_12_21_121519.noarch.rpm</code> (<strong><em>Job2</em></strong>) instead of the correct one (non extra one), as <code>-</code> character's order comes first due to ASCII sequence.</p>
  
  <p>I tested the regex and seeing why in the last command I didn't see expected output. Isn't <code>1?</code> in the regex going to give us any lines which has <code>arun</code> with either <code>0 or 1</code> occurrence of character <code>1</code>?</p>
  
  <pre><code>[giga@linux-server giga]# echo -e "arun\narun1\narun2\narun11" |grep "arun"
  arun
  arun1
  arun2
  arun11
  [giga@linux-server giga]#
  
  [giga@linux-server giga]# echo -e "arun\narun1\narun2\narun11" |grep "arun1"
  arun1
  arun11
  [giga@linux-server giga]#
  
  [giga@linux-server giga]# echo -e "arun\narun1\narun2\narun11" |grep "arun1?"
  [giga@linux-server giga]#
  </code></pre>
  
  <p><strong>Questions:</strong><br/>
  1. Why this works if I use <code>egrep</code>?<br/>
  2. Why it didn't work with <code>grep</code>, while <code>grep</code> man page / examples tells it supports it?<br/>
  3. What regex can I use so that if I pass <code>myrpm</code> as the job parameter's value, then it works in both Job1 and Job2 where rpm filename contains either the short and full rpm name.</p>
  
  <p>Here: <a href="https://www.cyberciti.biz/faq/grep-regular-expressions/" rel="nofollow noreferrer">https://www.cyberciti.biz/faq/grep-regular-expressions/</a> (search for <strong>grep Regular Expression Operator</strong>) and </p>
  
  <p><code>man grep</code> shows:</p>
  
  <pre><code>   Repetition
         A regular expression may be followed by one of several repetition operators:
         ---------------------------------------------------------------
         ?      The preceding item is optional and matched at most once.
         ---------------------------------------------------------------  
         *      The preceding item will be matched zero or more times.
         +      The preceding item will be matched one or more times.
         {n}    The preceding item is matched exactly n times.
         {n,}   The preceding item is matched n or more times.
         {,m}   The preceding item is matched at most m times.  This is a GNU extension.
         {n,m}  The preceding item is matched at least n times, but not more than m times.
  </code></pre>