*/
const MAX_LEN = 64;
+ /**
+ * Regex with non-capturing group that matches whitespace and some
+ * characters which are allowed right before an @ or ! when mentioning
+ * other users. Like: 'This goes out to:@mmn (@chimo too) (!awwyiss).'
+ *
+ * FIXME: Make this so you can have multiple whitespace but not multiple
+ * parenthesis or something. '(((@n_n@)))' might as well be a smiley.
+ */
+ const BEFORE_MENTIONS = '(?:^|[\s\.\,\:\;\[\(]+)';
+
/**
* Nice simple check of whether the given string is a valid input nickname,
* which can be normalized into an internally canonical form.
// @#tag => mention of all subscriptions tagged 'tag'
- preg_match_all('/(?:^|[\s\.\,\:\;]+)@#([\pL\pN_\-\.]{1,64})/',
+ preg_match_all('/'.Nickname::BEFORE_MENTIONS.'@#([\pL\pN_\-\.]{1,64})/',
$text, $hmatches, PREG_OFFSET_CAPTURE);
foreach ($hmatches[1] as $hmatch) {
$tag = common_canonical_tag($hmatch[0]);
'url' => $url);
}
- preg_match_all('/(?:^|[\s\.\,\:\;]+)!(' . Nickname::DISPLAY_FMT . ')/',
+ preg_match_all('/'.Nickname::BEFORE_MENTIONS.'!(' . Nickname::DISPLAY_FMT . ')/',
$text, $hmatches, PREG_OFFSET_CAPTURE);
foreach ($hmatches[1] as $hmatch) {
$nickname = Nickname::normalize($hmatch[0]);
$atmatches = array();
// the regexp's "(?!\@)" makes sure it doesn't matches the single "@remote" in "@remote@server.com"
- preg_match_all('/(?:^|\s+)@(' . Nickname::DISPLAY_FMT . ')\b(?!\@)/',
+ preg_match_all('/'.Nickname::BEFORE_MENTIONS.'@(' . Nickname::DISPLAY_FMT . ')\b(?!\@)/',
$text,
$atmatches,
PREG_OFFSET_CAPTURE);