Go (and consequently Hugo) supports only a limited set of RE expressions:
This \[.*?\]\((.*?)[\) ] does the trick: Non-capturing group (and those are supposed to work!), a non-greedy match for [.*](, followed by a capturing group matching .* non-greedily, followed by a closing parenthesis or a space (for image URLs). Beware though, that this expression will also catch image URLs, you might want to take care of that.
With REs, as with everything else, simpler is better. In your example, there’s no need whatsoever for non-capturing groups. Nor for Look-ahead/behind expressions. And yes, non-capturing groups do work. It might be worth it to double-check before stating that a product is at fault.
What I meant is I don’t see the point of your advice: why telling me to use expressions in hugo that do not work with hugo ? Non-capturing are recognized (eventhough I can’t make use of it with findRE) but look-aheads aren’t.
Beyond findRE giving a slice of all matches and this precise regexp working, the code below still produces empty cite expressions. To be precise, it doesn’t enter the {{with $inter}}{{end}} part. I would appreciate if someone could correct this, since I didin’t find the docu of findRE very helpful, so this is above my understanding.
{{ $author := .Attributes.author }}
{{ $class := .Attributes.class }}
{{ $complex := or (or $class (or $author (or .Attributes.cite .Attributes.id))) (not (in $class "simple")) }}
{{ if $complex }}<figure {{with .Attributes.id}}id={{.}} {{end}}class="non-picture {{with $class}}{{.}}{{end}}">{{end}}
<blockquote
{{ with .Attributes.cite }}
{{ $inter := index (findRE `\[.*?\]\((.*?)[\) ]` .) 0 }}
{{with $inter}}{{ printf "cite=\"%s\"" . | safeHTMLAttr }}
{{ end }}{{ end }}
>{{ .Inner|$.Page.RenderString }}</blockquote>
{{if $complex }}{{ if or $author .Attributes.cite }}<figcaption class=cite_class>{{with $author}}{{.|$.Page.RenderString }}{{end}}{{with .Attributes.cite }}<cite> in {{.|$.Page.RenderString}}</cite>{{end}}</figcaption>{{end}}
</figure>{{end}}
to successfully extract urls and put them in cite="..." ? An exemple:
```quote{cite="[moteur](www.aol.fr)"}
random junk
\```
(ignore the ""). this should produce a cite="www.aol.fr" html attribute.
Have a look at the Hugo documentation around findRe. I’m fairly confident that you’ll find an answer to your “royally ignored” question.
For me, your attitude makes trying to help you not very fun. Therefore, I’m out here.
{{ with .Attributes.cite }}
{{ $inter := replaceRE (?:\()([^]]*)(?:\)) “$1” (index (findRE (?:\[[^]]*]\()([^]]*)(?:\)) .) 0) }}
{{with $inter}}{{ printf “cite="%s"” . | safeHTMLAttr }}
{{ end }}{{ end }}
this still gives .Attributes.cite without modification, if it contains a link.
In my own opinion there should be more and simpler functions. Something aking to findRESubmatch, which would produce a slice of the groups matching. Use of regexps should be a straightforward as possible, because as is it’s not for normal folks, even courageous ones.
trim does not make sense when the prefix is not fixed (no pun intended). The OP does need an RE if their code is supposed to work with varying strings.
findRE will not help them there, findRESubmatch would.
the prefix is fixed, thanks to my links hook. Always starting by either http:// or https://.
I had not thought of those functions ! It’s as the saying goes: if your only tool is a hammer, every problem becomes a nail.
How about that?
That way I could even put an image or a detail shortcode call, and extract the url, like I always wanted. Pretty funky, but as long as the cite attribute is valid, who cares?
but for now it says “syntax error” for the first line, even after rearranging. I don’t see what’s wrong.
Usually they’re more verbose. So I can assume it’s not a matter of missing parenthesis ?
And yes, in blabka I want to extract URI, so the link (or image or whatever, no matter) can appear in but the cite attribute of the blockquote element is still an URL.
I wonder though, isn’t there a simpler way than index (last 1 (split .Attributes.cite "](")) 0) ) ? this looks stupidly convoluted. The function string can fuse all strings of an array into a string as what merge does for map.
Sorry, I assumed the separation of text and link as in text were handled by markdown and you just wanted to trim the scheme.
Should still be able to do it this way but you need to account for the case with no scheme present.