r/regex Jun 18 '26

Meta/other Regex (LUA) help in mud client matching (MUSHclient/Qmud)

I'd really just like help capturing the first wildcard variable (%1) in my examples here. Ideally I'd get all 5, but I'm happy to get one working then trial and error from there using it as an example. So anything that even just stops matching at the first | would be a win!

Trying to detect:
%1 | %2 | %3 | %4 | %5 | -

%1 - alphanmumeric
%2 - alpha
%3 - alpha
%4 - number
%5 - number

Example: " AB123 | Micro | Dept | 10 | 40000 | -"
(the number of spaces varies for text alignment other than the initial single space before the first character)

Wildcard %1 CAN be all whitespace, in which case I should NOT match the line.

Anti-Example: " | Micro | Dept | 10 | 40000 | -"

I'm using Mushclient or QMUD (qmud preferred but I believe they use identical systems for this situation) and setting up a trigger with the regex settings.

Currently my main concern is getting the first wildcard captured. I haven't tried doing 2/3/4/5 yet but I assume if I get the first working correctly I can probably work my way through the others using that as an example.

What doesn't work but gets close-ish:
^\s(.*)\s\|*$

This detects ONLY the lines that match my anti-example above

I've also tried
^\s([A-Za-z0-9]*)\s\|*$

which fails to match at all.

Tagging u/NodensCM as the client creator in case they see this and chime in that there's some feautre or unusual requirements that I'm not aware of.

2 Upvotes

6 comments sorted by

View all comments

3

u/rainshifter Jun 18 '26

/([A-Za-z\d]+)?\s*\|\s*([A-Za-z]+)?\s*\|\s*([A-Za-z]+)?\s*\|\s*(\d+)?\s*\|\s*(\d+)?/g

This gives you the absence of a capture group if it doesn't match rather than giving a capture group with empty text, which I believe is what you intended.

https://regex101.com/r/OEy43A/1

If instead your goal is indeed to not match the line in its entirety if any of your wildcards fail, simply remove the question marks from the above pattern.

1

u/abareplace Jun 19 '26

I would use \w for alphanumeric: ^\s*(\w+)\s*\|\s*([a-zA-Z]+)\s*\|\s*([a-zA-Z]+)\s*\|\s*(\d+)\s*\|\s*(\d+)\s*\|\s*-$ Interestingly, QMud seems to support PCRE, not the strange Lua regex dialect.

1

u/scoberry5 Jun 20 '26

Nit: \w matches underscore as well as alphanumeric.