regexluamud

How to match any room description with regular expression in Mushclient


I would like to generate a regular expression that matches with a room description like this:

My Room Description(enter, n, s, e and w)
My Room Description(enter, e, s, w and n)
My Room Description(s, w, e, n and enter)
My Room Description(n, e, w, s and enter)

The exit directions could be in different position but will always be the same amount (4) in this case.

This should not match:

My Room Description(n, up, e, w, s and enter)

because it has 5 exits (other than “enter”).


Solution

  • Try this:

    ^My Room Description\((\w+(, | and )?){5}\)$
    

    See live demo.

    ——-

    To allow optional leading text, such as "HP:245 EP:245 >> " as per your comment:

    ^[\w: >]*My Room Description\((\w+(, | and )?){5}\)$
    

    Or more strict:

    ^([\w: ]* >> )?My Room Description\((\w+(, | and )?){5}\)$
    

    This restricts the leading characters to only those you’ve provided as an example. To allow anything:

    ^.*My Room Description\((\w+(, | and )?){5}\)$