I would like to convert
Hello a/b hiintoHello \frac{a}{b} hia/b hiinto\frac{a}{b} hiHello a/bintoHello \frac{a}{b}
where a and b is any non space character, using Lua patterns.
I came up with a pattern for each of those 3 cases:
line, _ = string.gsub(line, "%s+(%S+)/(%S+)%s+", "\\frac{%1}{%2}")
line, _ = string.gsub(line, "^(%S+)/(%S+)%s+", "\\frac{%1}{%2}")
line, _ = string.gsub(line, "%s+(%S+)/(%S+)$", "\\frac{%1}{%2}")
Is it possible to condense them into a single regular expression?
Because [^%s] would resolve to the complement of the %s character class, that is, all non-space characters (equivalent to %S), rather than space or start of line.
One regular expression is:
Examples: