How to detect if a string has single asterisk "*" or a double "**" and getting its contents

Hello, currently I’m working on a string parser which includes extracting text between asterisks and using it for some purpose. Currently, this algorithm works.

local str = "get this text: *foo*"
local textGotten = str:match("%b**")
-- I am using the %bxy pattern in to detect the text between the asterisks.
-- Now, when i print(str) -> "foo"

But, what I’m trying to do is figure out how to detect “*text*” and “**text**” with the double asterisks. Unfortunately the %bxy pattern isn’t working for me, and I attempted to perhaps subsitute x for [**] and y for [**] for the pattern → “%b[**][**]”. As good of an attempt it was, this did not properly collect the text in between the double asterisk.

Is there a pattern I can use to capture text between a double, or even triple asterisk using pure string patterns/regex, without running the %b** pattern twice(which works, but is not ideal.)?

local strings = "*lol*"

if strings:match("%*.*%*") then
	print("Double asterisk enclosed string!")
end

%bxy is essentially useless, I have no idea why it was added with the other string pattern modifiers.

I use %bxy to output an array of all strings enclosed in for example multiple brackets or asterisks in one string which is much faster than doing the string.split method. Thanks!

Could you not use :gmatch() to iterate over sub-strings of a subject string which match a specific pattern? And no problem.