Hail, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the Achaea Forums! Please be sure to read the Forum Rules.

Regex help please?

SherazadSherazad Planef UrthMember Posts: 951 @ - Epic Achaean

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?

Trying to write about games, series, movies at Geeksauce Rocks! On hiatus D:
내가 제일 잘 나가!!!111!!1


Tagged:

Comments

  • SenaSena Member Posts: 3,927 @@ - Legendary Achaean
    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.

    SherazadAlcinae
  • SherazadSherazad Planef UrthMember Posts: 951 @ - Epic Achaean

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

    Trying to write about games, series, movies at Geeksauce Rocks! On hiatus D:
    내가 제일 잘 나가!!!111!!1


    AlcinaeDalran
Sign In to Comment.