{"name":"Arma 3: Regular Expressions","title":"Arma 3: Regular Expressions","type":"topic","url":"https://community.bistudio.com/wiki/Arma_3:_Regular_Expressions","revid":378124,"updated":"2026-02-21T14:28:26Z","aliases":[],"markdown":"Arma 3 v2.06\n\nA **Regular Expression** (or regex/regexp) is an advanced text search format involving specific codes.\n\n> [!NOTE]\n> - For a detailed explanation of what a Regular Expression (Regex) is, please visit [the Wikipedia page](https://en.wikipedia.org/wiki/Regular_expression) about it.\n> - The following pages allow to test regular expressions:\n>   - https://regexr.com/\n>   - https://regex101.com/\n\n### Quick Guide\n\n- `a` means \"the a character\"\n- `.` means \"any character\"\n- `.?` means \"any character zero or one time\"\n- `.+` means \"any character from one to infinity times\"\n- `.*` means \"any character zero to infinity times\"\n- `.{3,5`} means \"any (identical) character that is present three to five times\"\n- `[a c]` is a **group** and means \"a character that is **either** a **or** c **or** space\"\n- `[a-z]` is a **range** and means \"any character between a and z\" (**not** between A and Z in the event of a case-sensitive search!)\n- `[a-zA-Z0-9]` is a **range** and means \"any character between a and z **or** A and Z **or** 0 and 9\"\n- `[^a-z]` is a **negative range** and means \"any character **not** between a and z\"\n- `Arma [0-9]` means anything from \"Arma 0\" to \"Arma 9\" (going through 1, 2, 3, 4 etc)\n\n> [!NOTE]\n> To match a specific character that is used in regex syntax, escape it with `\\`, e.g `I\\.\\.\\. don't know\\?`\n\n### Commands\n\nSee Command Group: Strings - Regular Expression.\n\n### Flags\n\nIn order to adjust the behaviour of the regex commands, certain flags can be set when using them.\nFlags are specified at the end of the pattern and start with `/`. Flags need to be lowercase.\nIf there are any non-flag characters in the flags they will be ignored and considered part of the pattern itself.\n\n> [!NOTE]\n> If no flags are specified, the default flags are set to `g` and `i`.\n> It is valid to specify `/` to indicate no flags, first match only, case sensitive - see Examples.\n\n| Flag | Name | Description |\n|---|---|---|\n| g | Global | Only relevant for regexReplace and regexFind.<br>***Missing*** the global flag sets `format_first_only` flag [(source)](https://en.cppreference.com/w/cpp/regex/match_flag_type) and:<br>- **only replaces the first occurrence** with regexReplace<br>- **only returns the first element** with regexFind |\n| i | Case-insensitive | N/A |\n| n | noSubs | > « When performing matches, all marked sub-expressions (expr) are treated as non-marking sub-expressions (?:expr).<br>> No matches are stored in the supplied std::regex_match structure and mark_count() is zero » – c++ reference ([source](https://en.cppreference.com/w/cpp/regex/syntax_option_type)) |\n| o | Optimise | Optimise pattern, pattern creation is slower, but will execute more efficiently [(source)](https://en.cppreference.com/w/cpp/regex/syntax_option_type) |\n\n### Examples\n\n```sqf\n\"1, 42, and 10e10\" regexFind [\"[0-9]\"]; // matches \"1\", \"4\", \"2\", \"1\", \"0\" \"1\" and \"0\"\n```\n\n```sqf\n\"1, 42, and 10e10\" regexFind [\"[0-9]+\"]; // matches \"1\", \"42\", \"10\" and \"10\", avoiding commas and spaces\n```\n\n```sqf\n\"Hello there!\" regexMatch \"There\";        // matches - default flags g and i are active\n\"Hello there!\" regexMatch \"There/\";        // no flags are set - as \"There\" is different from \"there\" and search is case-sensitive, so the match fails\n\"Hello there!\" regexMatch \"There/i\";    // matches - only the i flag is active\n```\n\n```sqf\n\"I like garlic, onions and cheese\" regexFind [\"([^ ]+)(?:,| and) \"]; // matches \"garlic\" and \"onions\"\n```\n\n```sqf\n\"Existing Arma: Arma 0, ArmA, ArmA 1, Arma 1, Arma 2, Arma 3, Arma 4, Arma 5, Arma 2035\" regexFind [\"(Arma [0-3])[^0-9]/g\"]; // matches \"Arma 0\", \"Arma 1\", \"Arma 2\", \"Arma 3\"\n```","sections":[{"heading":null,"level":1,"markdown":"Arma 3 v2.06\n\nA **Regular Expression** (or regex/regexp) is an advanced text search format involving specific codes.\n\n> [!NOTE]\n> - For a detailed explanation of what a Regular Expression (Regex) is, please visit [the Wikipedia page](https://en.wikipedia.org/wiki/Regular_expression) about it.\n> - The following pages allow to test regular expressions:\n>   - https://regexr.com/\n>   - https://regex101.com/"},{"heading":"Quick Guide","level":3,"markdown":"- `a` means \"the a character\"\n- `.` means \"any character\"\n- `.?` means \"any character zero or one time\"\n- `.+` means \"any character from one to infinity times\"\n- `.*` means \"any character zero to infinity times\"\n- `.{3,5`} means \"any (identical) character that is present three to five times\"\n- `[a c]` is a **group** and means \"a character that is **either** a **or** c **or** space\"\n- `[a-z]` is a **range** and means \"any character between a and z\" (**not** between A and Z in the event of a case-sensitive search!)\n- `[a-zA-Z0-9]` is a **range** and means \"any character between a and z **or** A and Z **or** 0 and 9\"\n- `[^a-z]` is a **negative range** and means \"any character **not** between a and z\"\n- `Arma [0-9]` means anything from \"Arma 0\" to \"Arma 9\" (going through 1, 2, 3, 4 etc)\n\n> [!NOTE]\n> To match a specific character that is used in regex syntax, escape it with `\\`, e.g `I\\.\\.\\. don't know\\?`"},{"heading":"Commands","level":3,"markdown":"See Command Group: Strings - Regular Expression."},{"heading":"Flags","level":3,"markdown":"In order to adjust the behaviour of the regex commands, certain flags can be set when using them.\nFlags are specified at the end of the pattern and start with `/`. Flags need to be lowercase.\nIf there are any non-flag characters in the flags they will be ignored and considered part of the pattern itself.\n\n> [!NOTE]\n> If no flags are specified, the default flags are set to `g` and `i`.\n> It is valid to specify `/` to indicate no flags, first match only, case sensitive - see Examples.\n\n| Flag | Name | Description |\n|---|---|---|\n| g | Global | Only relevant for regexReplace and regexFind.<br>***Missing*** the global flag sets `format_first_only` flag [(source)](https://en.cppreference.com/w/cpp/regex/match_flag_type) and:<br>- **only replaces the first occurrence** with regexReplace<br>- **only returns the first element** with regexFind |\n| i | Case-insensitive | N/A |\n| n | noSubs | > « When performing matches, all marked sub-expressions (expr) are treated as non-marking sub-expressions (?:expr).<br>> No matches are stored in the supplied std::regex_match structure and mark_count() is zero » – c++ reference ([source](https://en.cppreference.com/w/cpp/regex/syntax_option_type)) |\n| o | Optimise | Optimise pattern, pattern creation is slower, but will execute more efficiently [(source)](https://en.cppreference.com/w/cpp/regex/syntax_option_type) |"},{"heading":"Examples","level":3,"markdown":"```sqf\n\"1, 42, and 10e10\" regexFind [\"[0-9]\"]; // matches \"1\", \"4\", \"2\", \"1\", \"0\" \"1\" and \"0\"\n```\n\n```sqf\n\"1, 42, and 10e10\" regexFind [\"[0-9]+\"]; // matches \"1\", \"42\", \"10\" and \"10\", avoiding commas and spaces\n```\n\n```sqf\n\"Hello there!\" regexMatch \"There\";        // matches - default flags g and i are active\n\"Hello there!\" regexMatch \"There/\";        // no flags are set - as \"There\" is different from \"there\" and search is case-sensitive, so the match fails\n\"Hello there!\" regexMatch \"There/i\";    // matches - only the i flag is active\n```\n\n```sqf\n\"I like garlic, onions and cheese\" regexFind [\"([^ ]+)(?:,| and) \"]; // matches \"garlic\" and \"onions\"\n```\n\n```sqf\n\"Existing Arma: Arma 0, ArmA, ArmA 1, Arma 1, Arma 2, Arma 3, Arma 4, Arma 5, Arma 2035\" regexFind [\"(Arma [0-3])[^0-9]/g\"]; // matches \"Arma 0\", \"Arma 1\", \"Arma 2\", \"Arma 3\"\n```"}],"categories":["Arma 3: Editing","Introduced with Arma 3 version 2.06"],"groups":["Scripting"]}