Regex help please?

I don't exactly know how to make this work in regex.

(You or any player full name) (happily, sadly or none) (whisper|say|exclaim) (to name of person you're speaking to or none) (in Mhaldorian or none) (in a whatever voice or none), "Stuff."

I'm having problems with the or none thing coupled with several things being needed. Help please?

Bleh, work ate my gaming life.
내가 제일 잘 나가!!!111!!1


  • edited June 2014

    I don't have the exact say lines for reference, so I can't make the exact pattern you'll want, but basically what you want is something like:

    ^(\w+) (happily |sadly )?(whispers?|says?|exclaims?)( to \w+)?( in Mhaldorian)?( in a [\w ]+ voice)?, ".+"$

    For some explanation of what that means: (thing|otherthing) will match either of the two options there. ? is a modifier that makes the previous pattern to match 0 or 1 times. So (thing|otherthing)? will match "thing", "otherthing" or nothing. You could also do (thing|otherthing|) to get the same result. \w+ matches any alphanumeric string (not spaces, so it will only match one word). [stuff] matches any of the characters within the brackets, in this case [\w ] matches any letters, numbers, or spaces, and the + after it means that it matches one or more of those characters.

    Edit: Two things I forgot to mention. ? after a normal character instead of a regex pattern applies only to that character, so "whispers?" will match "whisper" or "whispers". And the things in parentheses will be captured to %1, %2, etc. (or whatever your client uses), which you can avoid if you want to by adding ?: inside the parentheses, (?:thing|otherthing) for example.

  • SherazadSherazad Planef Urth

    Wow, thanks for the indepth explanation, @Sena! I can use that in other stuff too. :D

    Bleh, work ate my gaming life.
    내가 제일 잘 나가!!!111!!1

Sign In or Register to comment.