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

Need help matching.

VayneVayne Rhode IslandMember Posts: 1,897 @@ - Legendary Achaean
Basically, I'm trying to make an alias that allows me to either transmute all my chemicals on hand or a certain amount. Where I am stuck is with matching the regex with proper variables.

pattern:
^synth (.+) (.+)$

That is the pattern I have now. The first variable being the metal I want to synthesise and the second being the amount. The script is an if argument that is supposed to synth them all if matches[3] == nil and synth however many it is equal to otherwise. However, the pattern doesn't match if I just leave the second variable blank on the line (ex. synth tin). Obviously, I am not doing it right and was wondering if anyone could please tell me how or if I can either match nothing or a string like that. Thanks!
image

Comments

  • EldEld Member Posts: 3,946 @@ - Legendary Achaean
    .+ means "at least on character", so that pattern will only match if both arguments are there. I would probably use

        ^synth (\w+)(?: (\d+))?$

    The \w+ will match any set of alphanumeric characters (the name of the metal) and the \d+ will match any set of digits. The final ? makes everything in the preceding set of parentheses (i.e., the " (\d+)" part) optional, and the ?: at the beginning of that set of parentheses prevents it from being counted as a capture group. So what you're left with is "synth " followed by a word, optionally followed by another space and a number. The word is matches[2] and the number is matches[3], as with your original.

    VayneAntonius
Sign In to Comment.