RegExp puzzle

Posted by Neurowiz on Fri 03 Jan 2003 05:26 AM — 5 posts, 22,144 views.

#0
I'm inexperienced with regex, but I'm not quite certain how to pull this off:

There is a message that I might be afflicted with paralysis. Unfortunately, the way the game does it is to replace various letters with asterisks at random characters:

"A prickly stinging overcomes your body, fading away into numbness."

It will show up like so:

A *rick*y stin*ing *ver*comes ...

Anyway you get the idea.

Now originally, I set up a regex to look like so:
^(A|\*)( |\*)(p|\*)(r|\*)(i|\*)(c|\*)(k|\*)(l|\*)(y|\*).*$

Now this does work.. but with some unintended side effects... if I see a line of all asterisks, then the regex is interpreted to be true. I can't figure out how to make it work so that it would pick up when I have random characters in a line substituted by asterisks, and yet not a solid line of asterisks.

Any hints to get me in the right direction?

Thanks!
Regards,
Neurowiz
Russia #1
Hey, Neuro

This has already come up on this board before, so I'll just post the results of the previous discussion that I use now.

The trigger looks like:

^((?:A|\*)(?: |\*)(?:p|\*)(?:r|\*)(?:i|\*)(?:c|\*)(?:k|\*)(?:l|\*)(?:y|\*)(?: |\*)(?:s|\*)(?:t|\*)(?:i|\*)(?:n|\*)(?:g|\*)(?:i|\*)(?:n|\*)(?:g|\*)(?: |\*)(?:o|\*)(?:v|\*)(?:e|\*)(?:r|\*)(?:c|\*)(?:o|\*)(?:m|\*)(?:e|\*)(?:s|\*)(?: |\*)(?:y|\*)(?:o|\*)(?:u|\*)(?:r|\*)(?: |\*)(?:b|\*)(?:o|\*)(?:d|\*)(?:y|\*)(?:\,|\*)(?: |\*)(?:f|\*)(?:a|\*)(?:d|\*)(?:i|\*)(?:n|\*)(?:g|\*)(?: |\*)(?:a|\*)(?:w|\*)(?:a|\*)(?:y|\*)(?: |\*)(?:i|\*)(?:n|\*)(?:t|\*)(?:o|\*)(?: |\*)(?:n|\*)(?:u|\*)(?:m|\*)(?:b|\*)(?:n|\*)(?:e|\*)(?:s|\*)(?:s|\*)(?:\.|\*))$

This does match on an all-asterix line, but it must have a specific number of asterix in it. Basically, any char in the matched line can be either a certain letter, a space, a punctuation sign or an asterix. I am sure you get the idea.
'?' mean either-or.

There's actually another form of the same line, which has a * after the period and no newline, meaning that the prompt from the following line gets dragged into the end of the matched one. The trigger above can't handle that, so I used a non-regexp trigger to handle it. Obviously, it presumes that there's just one literal form of the message. I am not sure if that is the case, but I am using it for now. Here it is:

A prickly stingin* overwhelms your body, fading away *nto numbness*

Hope that helps.

Russia #2
Correction,

'|' mean either-or; '?' prevent you from getting a too-many-wildcards error, which you would otherwise get with that many parentheses in there.
Canada #3
Actually, it's the ?: together that indicate the pattern should be searched for, but NOT returned as a wildcard. I'm sure you know that Ked, since you use it in your example.
Russia #4
Thank you, Magnum. ? on its own certainly means something different - I need to start using RegExp more often, maybe then I won't have a dozen aliases for every little bit of code in my script file :)