lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


It looks like the '?' quantifier can only apply to a single character or class of characters, not a matching pattern like '#.+'

On Mon, 25 Jan 2021 at 14:45, Peter Matulis <pmatulis@gmail.com> wrote:


On Thu, 21 Jan 2021 at 11:53, Philippe Verdy <verdyp@gmail.com> wrote:
Note that Lua patterns do not support alternatives with '|', but they support  '?' for 0 or 1 occurrence (not just '*' and '+' for 0+ and 1+ occurences).
Note also that you want to match the dot for the extension literally, not arbitrary characters, so you must use '%.', not '.'. The '#' does not need to be escaped by a '%' in the search pattern (however it still works if you do).
Just create a capture group for the optional anchor (*including* the leading '#').

function Link (link)
  link.target = link.target:gsub('(.+)%.md(#.+)?', '%1.html%2')
  return link
end


This does not work for me. Neither of the alternatives are acted upon. How should I debug this?

/pm