From a984531ce57f30bc9ec7f664e7c2e8c77b3f439e Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Mon, 3 Feb 2025 13:56:57 +0100 Subject: url-mode: use the first *sub* expression as URL When auto-matching URLs (or custom regular expressions), use the first *subexpression* as URL, rather than the while regex match. This allows us to write custom regular expressions with prefix/suffix strings that should not be included in the presented match. --- url-mode.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'url-mode.c') diff --git a/url-mode.c b/url-mode.c index 3108ec12..0101de19 100644 --- a/url-mode.c +++ b/url-mode.c @@ -400,13 +400,13 @@ regex_detected(const struct terminal *term, enum url_action action, if (r == REG_NOMATCH) break; - const size_t mlen = matches[0].rm_eo - matches[0].rm_so; - const size_t start = &search_string[matches[0].rm_so] - v->utf8; + const size_t mlen = matches[1].rm_eo - matches[1].rm_so; + const size_t start = &search_string[matches[1].rm_so] - v->utf8; const size_t end = start + mlen; LOG_DBG( "regex match at row %d: %.*srow/col = %dx%d", - matches[0].rm_so, (int)mlen, &search_string[matches[0].rm_so], + matches[1].rm_so, (int)mlen, &search_string[matches[1].rm_so], v->map[start].row, v->map[start].col); tll_push_back( -- cgit v1.3