Quick Question about Regular Expressions

I think I’ve figured out what regular expression I need to search for – + – but while the page on regular expressions in the System Manual describes the construction of expressions in great detail, it never actually gives an example (unless my eyes glazed over for a moment, which is entirely possible) of how one would use a constructed expression in code. Somehow, I doubt this will work:

local r = '<digit>+'; if (str == r) ...

So how exactly do I invoke or initiate regular expression matching?

use rexSearch(pat, str, index?)

See tads.org/t3doc/doc/sysman/tadsgen.htm

Got it. Thanks! I think it’s working now.

Or almost. Finding the number in a gLiteral now works. But in revising my LiteralAction code I’ve inadvertently overwritten the normal output that transpires if the player tries to examine something that’s not in scope. I wanted to allow for the possible input ‘x page 18’, which means including ‘x’ and ‘examine’ as commands for the LiteralAction. I can probably manage a workaround for that as well, by including the word ‘page’ in the VerbRule…

If I didn’t need this darn puzzle, I’d do something simpler!

You can also use a regular expression in the definition of a TopicEntry. For example, the following might go some way to meeting your requirement:

++ ConsultTopic 'page <digit>+'
        local num = gTopicText.split(' ')[2];
        num = toInteger(num);
        if(num > 100)
            "There aren't that many pages in the book. ";
            "You find nothing of interest on page <<num>> ";

You might then be able to use this with a TopicTAction instead of trying to parse a LiteralTAction (or LiteralAction) in your own code.

Thanks, Eric. That may come in handy as I fine-tune this puzzle. Right now I’m off on a different tack, adding rooms and scenery.