StringMatching - arkayenro/arkinventory GitHub Wiki

String Matching

because the rule formulas are being interpreted via Lua there are some things you need to be aware of when trying to match strings, ie from name() and tooltip()

there are a few "magic" characters, these are ^$()%.[]*+-? if you want to search for one of these characters you must "escape" it or it won't match (and could do something totally different), you do this by putting a % in front of it. the same usually applies for any non alpha or numeric character.

eg; if looking for an item with "Mana-Etched" or "Giantstalker's" in an items name you would need to use name( mana%-etched, giantstalker%'s )

there are also several "character classes", these are used match a single character from it's class

  • : (where "" is not one of the magic characters ^$()%.[]*+-?) matches the character "" itself.

  • %∆: (where "" is any non-alphanumeric character) represents the character "". This is the standard way to escape the magic characters. Any punctuation character (even the non magic) can be preceded by a % when used to represent itself in a pattern.

  • .: (a fullstop/period/dot) represents any character (will match anything).

  • %a: represents all letters.

  • %d: represents all digits.

  • %p: represents all punctuation characters.

  • %s: represents all space characters.

  • %w: represents all alphanumeric characters.

  • %x: represents all hexadecimal digits.

the above "character classes" will only match on a single character, when you need to match more than one character you just add one of the following symbols directly after the class;

  • * matches 0 or more repetitions of characters in the class. Will always match the longest possible sequence.
  • + matches 1 or more repetitions of characters in the class. Will always match the longest possible sequence.
  • - matches 0 or more repetitions of characters in the class. Will always match the shortest possible sequence.
  • ? matches 0 or 1 occurrence of a character in the class.

you can make these patterns as simple or as complex as you need to match the specific piece of text you're after.

if you need more information you should google "lua string pattern" as there is a wealth of information already out there that goes into minute detail that would easily fill this page up by itself.