Wildcard String Searches

I am trying to buiild a conversation method using inputline - I want to do a regex string search but so far nothing is working. I am currently doing a String find (inp = the inputline):

I am looking for variants of:
‘How do you know my name?’
‘How do you know what my name is?’… etc

using:

inp.find(R’%MY NAME%?’) != nil

The above finds the first statement but not the second. Shouldn’t % denote a wildcard?
I have tried rexMatch etc, nothing.

Any ideas on doing more powerful string matching?

Thanks in advance!

Can’t you use SpecialTopic instead? Put it in a ConvNode which you activate before the player is supposed to give an answer.

See tads.org/t3doc/doc/tourguide … ltopic.htm

No, percent sign does not denote any kind of wildcard in regular expression, but rather denotes special matches together with letter or symbol written after, or backreference with number. For example %b denotes a word boundary, which means that it sits on the boundary between word characters and whitespace or other non-word characters. Regular expression have three main repetition symbols - * means zero or more repetitions are allowed, + means one or more repetition and ? means zero or one, but no repetition. You place one of those symbols immediately after character or group you are repeating. Try the following:

inp.find(R'<NoCase>%bmy +name%b')

RealNC: I probably could, I am still trying to learn the various conversation tools / methods - so any perceived limitations may just be my ignorance.

tomasb: Thanks! I’ll have to do a bunch of reading on Regex in TADS 3 - Your code works great but Regex seems to be completely different from what I now in other languages, I tried tweaking your expression above and it quickly broke down lol. But that is enough to get me going, and as I dig in more I can expand upon it or use built in topics, specialtopics, or asktell tools etc.

Thanks!

For some reason TADS have a quite a few differences in regular expression syntax, I’m not sure why, probably not to collide with syntax for strings and things embedded in strings. Nonetheless the principle is the same. More notable differences are:

  • Character classes are specified in angle braces, like , or instead of [[:alpha:]], [[:upper:]] or [[:space:]].
  • Instead of shorthands like \w, \b or \s you write %w, %b or %s.
  • Backreference is %1 instead of \1 or instead of $1

Other things are same in both TADS and major regex implementations in other programming languages. Meaning of * + ? is same, dot meaning is same, character classes such as [a-z] is same, grouping and alteration such as (abc|def) is also same and so on.

You shouldn’t have much trouble adapting standard regex syntax to TADS variant. I don’t know how strong you are in writing regexes, but you can get good insight in regular expressions by using interactive tools such as https://regex101.com/ which is one of the best. Of course the tool doesn’t have TADS specific syntax, but still it can help you understand principle and test regex beforehand.

Feel free to post regex related problems here, I’ll try to unbroke your code :slight_smile: (But RealNC’s suggestion is valid, maybe you are solving something which is not necessary.)

Thank you so much for the explanation. I think until I can move my code to with TADS intended conversation paradigm (er … insert correct term here lol), the advice above will allow me to accomplish what I need. As I get better in TADS - I’ll go back into my ‘characters’ directory and improve the conversations… hopefully add some semblance of AI.

Thanks again!

And tomasb, will do!