Quick help

by Lilia

Back to Mechanic's Corner.

Lilia2010-08-05 02:05:58
I want to capture this:

(Ship): \\w+ says, "Target (\\w+)."

Where do I add the slash to escape special characters and is it \\ or /?
Unknown2010-08-05 02:16:49
QUOTE (Lilia @ Aug 4 2010, 10:05 PM) <{POST_SNAPBACK}>
I want to capture this:

(Ship): \\w+ says, "Target (\\w+)."

Where do I add the slash to escape special characters and is it \\ or /?



Mudlet, right?

The pattern type is perl regex, and the pattern would be

^\\(Ship\\): \\w+ says, "Target (\\w+)\\."$


The captured thing to target then would be stored as the string matches. So if you wish to use it elsewhere in your code, you could do the following:

turTarget = matches

and then use the variable turTarget wherever you would instead put the name of the thing to target.

if any of that is unclear, lemme know, and I'll try again. I'm not the best at elucidation.
Lilia2010-08-05 02:28:48
That's perfect. I get confused about where to put the \\s
Unknown2010-08-05 02:37:33
QUOTE (Lilia @ Aug 4 2010, 10:28 PM) <{POST_SNAPBACK}>
That's perfect. I get confused about where to put the \\s


The easiest rule of thumb is "if it's used as a special regex character somewhere, escape it"

so ( , ) , \\ , . , + , and * are the main ones.