Regular Expressions – Arma 3
Jump to navigation
Jump to search
m (Fixed Wikipedia link) |
Lou Montana (talk | contribs) m (Text replacement - "\[ *(https?:\/\/[^ = ]+) +([^= ]+) *\]" to "{{Link|$1|$2}}") |
||
Line 42: | Line 42: | ||
| g | | g | ||
| Global | | Global | ||
| Only relevant for [[regexReplace]] and [[regexFind]]. '''''Missing''''' the global flag sets {{hl|format_first_only}} flag | | Only relevant for [[regexReplace]] and [[regexFind]]. '''''Missing''''' the global flag sets {{hl|format_first_only}} flag {{Link|https://en.cppreference.com/w/cpp/regex/match_flag_type|(source)}} and: | ||
* '''only replaces the first occurrence''' with [[regexReplace]] | * '''only replaces the first occurrence''' with [[regexReplace]] | ||
* '''only returns the first element''' with [[regexFind]] | * '''only returns the first element''' with [[regexFind]] | ||
Line 56: | Line 56: | ||
| o | | o | ||
| Optimize | | Optimize | ||
| Optimize pattern, pattern creation is slower, but will execute more efficiently | | Optimize pattern, pattern creation is slower, but will execute more efficiently {{Link|https://en.cppreference.com/w/cpp/regex/syntax_option_type|(source)}} | ||
|} | |} | ||
Revision as of 15:08, 28 April 2023
A Regular Expression (or regex/regexp) is an advanced text search format involving specific codes.
Quick Guide
- a means "the a character"
- . means "any character"
- .? means "any character zero or one time"
- .+ means "any character from one to infinity times"
- .* means "any character zero to infinity times"
- .{3,5} means "any (identical) character that is present three to five times"
- [a c] is a group and means "a character that is either a or c or space"
- [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!)
- [a-zA-Z0-9] is a range and means "any character between a and z or A and Z or 0 and 9"
- [^a-z] is a negative range and means "any character not between a and z"
- Arma [0-9] means anything from "Arma 0" to "Arma 9" (going through 1, 2, 3, 4 etc)
Commands
See Command Group: Strings - Regular Expression.
Flags
In order to adjust the behaviour of the regex commands, certain flags can be set when using them. Flags are specified at the end of the pattern and start with
Flag | Name | Description |
---|---|---|
g | Global | Only relevant for regexReplace and regexFind. Missing the global flag sets format_first_only flag (source) and:
|
i | Case-insensitive | N/A |
n | noSubs | |
o | Optimize | Optimize pattern, pattern creation is slower, but will execute more efficiently (source) |
Examples
"1, 42, and 10e10" regexFind ["[0-9]+"]; // matches "1", "42", "10" and "10", avoiding commas and spaces
"Hello there!" regexMatch "There"; // matches - default flags g and i are active
"Hello there!" regexMatch "There/"; // no flags are set - as "There" is different from "there" and search is case-sensitive, so the match fails
"Hello there!" regexMatch "There/i"; // matches - only the i flag is active
"I like garlic, onions and cheese" regexFind ["([^ ]+)(?:,| and) "]; // matches "garlic" and "onions"
"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"