atom/language-gfm — pull request #16 by andytlr (2014-03-30 00:41:32+00:00)
Title: Refinements to mention and issue matching

## Refinements to mention and issue matching

These have got pretty gnarly but they work much better:

```diff
- 'match': '(?<=^|\\s)(@)(\\w+)(\\s|\')'
+ 'match': '(?<=^|\\s|\"|\'|\\(|\\[)(@)(\\w+)(?=\\s|\"|\'|\.|\,|\\)|\\])'
```

```diff
- 'match': '(?<=^|\\s)(#)([0-9]+)(\\s|\')'
+ 'match': '(?<=^|\\s|\"|\'|\\(|\\[)(#)(\\d+)(?=\\s|\"|\'|\.|\,|\\)|\\])'
```

### Valid

#11 '#11' "#11" #11's #11. #11, (#11) [#11]
@bob '@bob' "@bob" @bob's @bob. @bob, (@bob) [@bob]

![screenshot 2014-03-30 11 24 19](https://cloud.githubusercontent.com/assets/475255/2560058/cc22e8da-b7a1-11e3-8ca6-227e73a9dcf8.png)

### Invalid

When there is an invalid character before the match like a#12 or b@bob they don't match (as expected). However if there is an invalid character following like #12a or @bob/ they still match.

![screenshot 2014-03-30 11 27 17](https://cloud.githubusercontent.com/assets/475255/2560059/e12bd49e-b7a1-11e3-8af4-b96f87e77fbb.png)

The first group (`(?<=^|\\s|\"|\'|\\(|\\[)`) uses a lookbehind (as suggested) and the last group (`(?=\\s|\"|\'|\.|\,|\\)|\\])`) uses a lookahead. But, from [regular-expressions.info](http://www.regular-expressions.info/lookaround.html):

> Positive lookahead works just the same. q(?=u) matches a q that is followed by a u, without making the u part of the match. The positive lookahead construct is a pair of parentheses, with the opening parenthesis followed by a question mark and an equals sign.`

And maybe a clearer explination from [MDN](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/RegExp):

> x(?=y)
>
> Matches x only if x is followed by y. For example, /Jack(?=Sprat)/ matches 'Jack' only if it is followed by 'Sprat'. /Jack(?=Sprat|Frost)/ matches 'Jack' only if it is followed by 'Sprat' or 'Frost'. However, neither 'Sprat' nor 'Frost' is part of the match results.

I'm super new to regex but I'm fairly sure I'm doing this correctly.

Any idea why they still match?

There are two commented out specs that test for these two cases.