# Global variables - available to all commands [variables] foobar = 4 multiply = 1.5 prefix = 'NEW_' enabled = true # Multi-regex example using variable in Lua [[commands]] name = 'RFToolsMultiply' regexes = [ 'generatePerTick = !num', 'ticksPer\w+ = !num', 'generatorRFPerTick = !num', ] lua = '* foobar' files = [ 'polymc/instances/**/rftools*.toml', 'polymc\instances\**\rftools*.toml', ] reset = true # Named capture groups with arithmetic and string ops [[commands]] name = 'UpdateAmountsAndItems' regex = '(?P!num)\s+units\s+of\s+(?P[A-Za-z_\-]+)' lua = 'amount = amount * multiply; item = upper(item); return true' files = ['data/**/*.txt'] # Full replacement via Lua 'replacement' variable [[commands]] name = 'BumpMinorVersion' regex = 'version\s*=\s*"(?P!num)\.(?P!num)\.(?P!num)"' lua = 'replacement = format("version=\"%s.%s.%s\"", major, num(minor)+1, 0); return true' files = ['config/*.ini', 'config/*.cfg'] # TOML multiline regex example - single quotes make regex natural! [[commands]] name = 'StressValues' regex = ''' \[kinetics\.stressValues\.v2\.capacity\] steam_engine = !num water_wheel = !num copper_valve_handle = !num hand_crank = !num creative_motor = !num''' lua = 'v1 * multiply' files = ['*.txt'] isolate = true # Network configuration with complex multiline regex [[commands]] name = 'NetworkConfig' regex = ''' networking\.firewall\.allowPing = true networking\.firewall\.allowedTCPPorts = \[ 47984 47989 47990 \] networking\.firewall\.allowedUDPPortRanges = \[ \{ from = \d+; to = \d+; \} \{ from = 8000; to = 8010; \} \]''' lua = "replacement = string.gsub(block[1], 'true', 'false')" files = ['*.conf'] isolate = true # Simple regex with single quotes - no escaping needed! [[commands]] name = 'EnableFlags' regex = 'enabled\s*=\s*(true|false)' lua = '= enabled' files = ['**/*.toml'] # Demonstrate NoDedup to allow overlapping replacements [[commands]] name = 'OverlappingGroups' regex = '(?P!num)(?P!num)' lua = 'a = num(a) + 1; b = num(b) + 1; return true' files = ['overlap/**/*.txt'] nodedup = true # Isolate command example operating on entire matched block [[commands]] name = 'IsolateUppercaseBlock' regex = '''BEGIN (?P!any) END''' lua = 'block = upper(block); return true' files = ['logs/**/*.log'] loglevel = 'TRACE' isolate = true # Using !rep placeholder and arrays of files [[commands]] name = 'RepeatPlaceholderExample' regex = 'name: (.*) !rep(, .* , 2)' lua = '-- no-op, just demonstrate placeholder; return false' files = ['lists/**/*.yml', 'lists/**/*.yaml'] # Using string variable in Lua expression [[commands]] name = 'PrefixKeys' regex = '(?P[A-Za-z0-9_]+)\s*=' lua = 'key = prefix .. key; return true' files = ['**/*.properties'] # JSON mode examples - modify single field [[commands]] name = 'JSONModifyField' json = true lua = ''' data.value = 84 modified = true ''' files = ['data/**/*.json'] # JSON mode - add new field [[commands]] name = 'JSONAddField' json = true lua = ''' data.newField = "added" modified = true ''' files = ['config/**/*.json'] # JSON mode - modify nested fields [[commands]] name = 'JSONNestedModify' json = true lua = ''' if data.config and data.config.settings then data.config.settings.enabled = true data.config.settings.timeout = 60 modified = true end ''' files = ['settings/**/*.json'] # JSON mode - modify array elements [[commands]] name = 'JSONArrayMultiply' json = true lua = ''' if data.items then for i, item in ipairs(data.items) do data.items[i].value = item.value * multiply end modified = true end ''' files = ['data/**/*.json'] # JSON mode - modify object version [[commands]] name = 'JSONObjectUpdate' json = true lua = ''' data.version = "2.0.0" data.enabled = enabled modified = true ''' files = ['config/**/*.json'] # JSON mode - surgical editing of specific row [[commands]] name = 'JSONSurgicalEdit' json = true lua = ''' if data.Rows and data.Rows[1] then data.Rows[1].Weight = 999 modified = true end ''' files = ['items/**/*.json'] # CSV processing example - read, modify, write [[commands]] name = 'CSVProcess' regex = '(?P!any)' lua = ''' local rows = fromCSV(csv, { hasheader = true }) for i, row in ipairs(rows) do if row.Value then row.Value = num(row.Value) * multiply end end replacement = toCSV(rows, { hasheader = true }) return true ''' files = ['data/**/*.csv'] # CSV processing with custom delimiter (TSV) [[commands]] name = 'TSVProcess' regex = '(?P!any)' lua = ''' local rows = fromCSV(tsv, { delimiter = "\t", hasheader = true, hascomments = true }) for i, row in ipairs(rows) do if row.Price then row.Price = num(row.Price) * 1.1 end end replacement = toCSV(rows, { delimiter = "\t", hasheader = true }) return true ''' files = ['data/**/*.tsv'] # CSV processing - modify specific columns [[commands]] name = 'CSVModifyColumns' regex = '(?P!any)' lua = ''' local rows = fromCSV(csv, { hasheader = true }) for i, row in ipairs(rows) do if row.Name then row.Name = prefix .. row.Name end if row.Status then row.Status = upper(row.Status) end end replacement = toCSV(rows, { hasheader = true }) return true ''' files = ['exports/**/*.csv']