core: add ${re:#} to get the index of last group captured in evaluation of expressions

v2.8-utf8proc
Sébastien Helleu 2017-03-30 22:13:14 +02:00
parent f0c8da2f05
commit bb00b6b8fb
6 changed files with 62 additions and 12 deletions

View File

@ -2058,9 +2058,18 @@ expanded to last):
| `+${re:N}+` |
Regex captured group: `0` = whole string matching, `1` to `99` = group
captured, `+++` = last group captured. |
`+${re:1}+` |
`+test+`
captured, `+++` = last group captured,
`#` = index of last group captured (_WeeChat ≥ 1.8_). |
`+${re:0}+` +
`+${re:1}+` +
`+${re:2}+` +
`+${re:+++}+` +
`+${re:#}+` |
`+test1 test2+` +
`+test1+` +
`+test2+` +
`+test2+` +
`+2+`
| `+${color:name}+` |
WeeChat color code (the name of color has optional attributes),

View File

@ -2101,9 +2101,18 @@ première étendue à la dernière) :
| `+${re:N}+` |
Groupe regex capturé : `0` = toute la chaîne correspondante,
`1` à `99` = groupe capturé, `+++` = dernier groupe capturé. |
`+${re:1}+` |
`+test+`
`1` à `99` = groupe capturé, `+++` = dernier groupe capturé,
`#` = index du dernier groupe capturé (_WeeChat ≥ 1.8_). |
`+${re:0}+` +
`+${re:1}+` +
`+${re:2}+` +
`+${re:+++}+` +
`+${re:#}+` |
`+test1 test2+` +
`+test1+` +
`+test2+` +
`+test2+` +
`+2+`
| `+${color:nom}+` |
Code couleur WeeChat (le nom de couleur a des attributs facultatifs),

View File

@ -2136,9 +2136,18 @@ expanded to last):
| `+${re:N}+` |
Regex captured group: `0` = whole string matching, `1` to `99` = group
captured, `+++` = last group captured. |
`+${re:1}+` |
`+test+`
captured, `+++` = last group captured,
`#` = index of last group captured (_WeeChat ≥ 1.8_). |
`+${re:0}+` +
`+${re:1}+` +
`+${re:2}+` +
`+${re:+++}+` +
`+${re:#}+` |
`+test1 test2+` +
`+test1+` +
`+test2+` +
`+test2+` +
`+2+`
| `+${color:name}+` |
WeeChat color code (the name of color has optional attributes),

View File

@ -2064,11 +2064,21 @@ char *weechat_string_eval_expression (const char *expr,
`+this…+` +
`+こ>>+`
// TRANSLATION MISSING
| `+${re:N}+` |
正規表現のキャプチャグループ: `0` = マッチするすべての文字列、`1` から `99` =
キャプチャされたグループ、`+++` = 最後にキャプチャされたグループ |
`+${re:1}+` |
`+test+`
キャプチャされたグループ、`+++` = 最後にキャプチャされたグループ、
`#` = index of last group captured (_WeeChat ≥ 1.8_). |
`+${re:0}+` +
`+${re:1}+` +
`+${re:2}+` +
`+${re:+++}+` +
`+${re:#}+` |
`+test1 test2+` +
`+test1+` +
`+test2+` +
`+test2+` +
`+2+`
| `+${color:name}+` |
WeeChat 色コード (色名部分はオプション属性をとることも可能です),

View File

@ -464,6 +464,12 @@ eval_replace_vars_cb (void *data, const char *text)
{
if (strcmp (text + 3, "+") == 0)
number = eval_regex->last_match;
else if (strcmp (text + 3, "#") == 0)
{
snprintf (str_value, sizeof (str_value),
"%d", eval_regex->last_match);
return strdup (str_value);
}
else
{
number = strtol (text + 3, &error, 10);

View File

@ -402,6 +402,13 @@ TEST(Eval, EvalReplaceRegex)
"password=abc password=def");
regfree (&regex);
/* regex groups */
hashtable_remove (pointers, "regex");
hashtable_set (options, "regex", "([a-z]+) ([a-z]+) ([a-z]+) ([a-z]+)");
hashtable_set (options, "regex_replace",
"${re:0} -- ${re:1} ${re:+} (${re:#})");
WEE_CHECK_EVAL("abc def ghi jkl -- abc jkl (4)", "abc def ghi jkl");
hashtable_free (pointers);
hashtable_free (extra_vars);
hashtable_free (options);