Regexes truly are write-only.

\[(.+?)\]\(<?(.+?)\.md>?\) does a shockingly simple thing for how opaque it is to look at.

To explain: this takes a markdown link in the format [Text](address.md) and extracts 'Text' and 'address' as matching groups I plan to use in some code to rewrite the link into a different format.

\[ \] \( and \) are literal bracket/paren matches. (.+?) means "Take one or more characters that match here, but as few as possible to meet the condition (in this case literally 'all characters between [ and ]'). <? and >? mean "match < and > if they're there. If they're not, cool".

And I know this isn't optimal even. I should remove \] from the matching set in the match groups, but meh.
Show thread
Follow

@trysdyn What's the difference between '+?' and '*'?

@rlamacraft The former requires at least one character in the match. * can match 0.

@trysdyn Oh right, so the question mark doesn't mean 0 or 1 of these here, instead it makes the plus lazy thereby ensuring it doesn't consume the period before the "md"? You're not wrong, regexs are really complex in subtle ways

Sign in to participate in the conversation
Qoto Mastodon

QOTO: Question Others to Teach Ourselves
An inclusive, Academic Freedom, instance
All cultures welcome.
Hate speech and harassment strictly forbidden.