mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-23 14:00:56 +01:00
Extract out regex from PhabricatorRemarkupRuleMention
Summary: I'd like to use this regex elsewhere and copying and pasting is bad. Test Plan: none Reviewers: casey, epriestley Reviewed By: epriestley CC: aran, epriestley Differential Revision: https://secure.phabricator.com/D2038
This commit is contained in:
parent
e696619dd1
commit
fa2467e8fe
1 changed files with 9 additions and 9 deletions
|
@ -27,17 +27,17 @@ final class PhabricatorRemarkupRuleMention
|
||||||
|
|
||||||
const KEY_MENTIONED = 'phabricator.mentioned-user-phids';
|
const KEY_MENTIONED = 'phabricator.mentioned-user-phids';
|
||||||
|
|
||||||
|
|
||||||
|
// NOTE: Negative lookahead for period prevents us from picking up email
|
||||||
|
// addresses, while allowing constructs like "@tomo, lol". The negative
|
||||||
|
// lookbehind for a word character prevents us from matching "mail@lists"
|
||||||
|
// while allowing "@tomo/@mroch". The negative lookahead prevents us from
|
||||||
|
// matching "@joe.com" while allowing us to match "hey, @joe.".
|
||||||
|
const REGEX = '/(?<!\w)@([a-zA-Z0-9]+)\b(?![.]\w)/';
|
||||||
|
|
||||||
public function apply($text) {
|
public function apply($text) {
|
||||||
|
|
||||||
// NOTE: Negative lookahead for period prevents us from picking up email
|
|
||||||
// addresses, while allowing constructs like "@tomo, lol". The negative
|
|
||||||
// lookbehind for a word character prevents us from matching "mail@lists"
|
|
||||||
// while allowing "@tomo/@mroch". The negative lookahead prevents us from
|
|
||||||
// matching "@joe.com" while allowing us to match "hey, @joe.".
|
|
||||||
$regexp = '/(?<!\w)@([a-zA-Z0-9]+)\b(?![.]\w)/';
|
|
||||||
|
|
||||||
return preg_replace_callback(
|
return preg_replace_callback(
|
||||||
$regexp,
|
self::REGEX,
|
||||||
array($this, 'markupMention'),
|
array($this, 'markupMention'),
|
||||||
$text);
|
$text);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue