title: Finding the index after matching substring in R
body: <p>I'm using the grep command to check whether a string is present in a list.</p>
  
  <pre><code>a &lt;- list("IK" , "IK /// CHGB ", "IKM" ,"HGIKGF", "IK2" ,"IK2FGH" )
  </code></pre>
  
  <p>I am trying to obtain the index of the strings which contain the substring "IK" using grep</p>
  
  <pre><code>grep("IK",a) 
  </code></pre>
  
  <p>gives</p>
  
  <pre><code>[1] 1 2 3 4 5 6
  </code></pre>
  
  <p>I would like to get the index of strings that contain only "IK" or "IK" followed by a single character or separated by /// e.g <code>"IK /// CHGB" , "IK2"</code> <code>and "IKM"</code>. I don't intend to output the index of a strings like <code>"HGIKGF" or "IKHGFTR /// BN"</code>.</p>
  
  <p>The desired output is </p>
  
  <pre><code>[1] 1 2 3 5
  </code></pre>
  
  <p>I would like to ask for suggestions on how this can be done.</p>
  
  <p>Edit1: Please note, the string that I am matching for "IK" is stored in a list.</p>
  
  <pre><code>Matchfor &lt;- list("IK","UK")
  for(j in 1:length(Matchfor){
  grep(Matchfor[j],a)
  }
  </code></pre>