title: Regex: Use start of line/end of line signs (^ or $) in different context
body: <p>While doing some small regex task I came upon this problem. I have a string that is a list of tags that looks e.g like this:<br>
      <code>foo,bar,qux,garp,wobble,thud</code></p>
  
  <p>What I needed to do was to check if a certain tag, e.g. 'garp' was in this list. (What it finally matches is not really important, just if there is a match or not.)</p>
  
  <p>My first and a bit stupid try at this was to use the following regex:<br>
      <code>[^,]garp[,$]</code></p>
  
  <p>My idea was that before 'garp' there should either be the start of the line/string or a comma, after 'garp' there should be either a comma or the end of the line/string.</p>
  
  <p>Now, it is instantly obvious that this regex is wrong: Both ^ and $ change their behaviour in the context of the character class [ ].</p>
  
  <p>What I finally came up with is the following:<br>
      <code>^garp$|^garp,|,garp,|,garp$</code></p>
  
  <p>This regex just handles the 4 cases one by one. (Tag at beginning of list, in the center, at the end, or as the only element of the list.) The last regex is somehow a bit ugly in my eyes and just for funs sake I'd like to make it a bit more elegant.</p>
  
  <p>Is there a way how the start of line/end of line characters (^ and $) can be used in the context of character classes?</p>
  
  <p>EDIT:
  Ok, some more info was wished so here it is:
  I'm using this within an Oracle SQL statement. This sadly does not allow any look-around assertions but as I'm only interested if there is a match or not (and not what is matched) this does not really affect me here.
  The tags can contain non-alphabetical characters like - or _ so \bgarp\b would not work. Also one tag can contain an other tag as SilentGhost said, so /garp/ doesnt work either.</p>