title: Python regex - identifying words with preceding symbol
body: <p>I am trying to split a target sentence into composite pieces for a later function using re.split() and the regex</p>
  <blockquote>
  <p>(@?\w+)(\W+)</p>
  </blockquote>
  <p>Ideally, this would split words and non-word characters in a generated list, preserving both as separate list items, with the exception of the &quot;@&quot; symbol which could precede a word. If there is an @ symbol before a word, I want to keep it as a cohesive item in the split. My example is below.</p>
  <p>My test sentence is as follows:</p>
  <blockquote>
  <p>this is a test of proper nouns @Ryan</p>
  </blockquote>
  <p>So the line of code is:</p>
  <blockquote>
  <p>re.split(r'(@?\w+)(\W+)', &quot;this is a test of proper nouns @Ryan&quot;)</p>
  </blockquote>
  <p>The list that I want to generate would include &quot;@Ryan&quot; as a single item but, instead, it looks like this</p>
  <blockquote>
  <p>['', 'this', ' ', '', 'is', ' ', '', 'a', ' ', '', 'test', ' ', '', 'of', ' ', '', 'proper', ' ', '', 'nouns', ' @', 'Ryan']</p>
  </blockquote>
  <p>Since the first container has the @ symbol, I would have thought that it would be evaluated first but that is apparently not the case. I have tried using lookaheads or removing @ from the \W+ container to no avail.</p>
  <p><a href="https://regex101.com/r/LeezvP/1" rel="nofollow noreferrer">https://regex101.com/r/LeezvP/1</a></p>