I'm looking to extract text surrounded by % symbols without any whitespace between them.
For example, this should match:
%link%
But this shouldn't:
%my link%
An easy regex solution would be:
/%\S*%/g
However, there's a requirement to include a prefix: % and a suffix: % in the regex pattern but keep it within these brackets: (.+?) (which is mandated by a third-party script).
So I need to modify the regex as follows:
/%(.+?)%/
Due to the limitation of "(.+?)", I need a workaround. Any suggestions?
UPDATE: The ideal regex should meet the following criteria:
regex = /%(.+?)%/g // default regex allowing spaces (needs improvement)
regex.test('%link%')
regex.test('%my link%') === false
regex.toString().includes('(.+?)')