Difference between revisions of "Category:Command Group: Strings - Regular Expression"

From Bohemia Interactive Community
Jump to navigation Jump to search
m
Line 1: Line 1:
patterns can have flags, similar to Javascript by specifying /flags at the end of the pattern.
+
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 <tt>/</tt>. Flags need to be lowercase. If there are any non-flag characters in the flags they will be ignored and considered part of the pattern itself.
Flags need to be lowercase, if there are any non-flag characters in the flags they will be ignored and considered part of the pattern itself.
+
<code>"I'm a coOkIe clicker" [[regexMatch]] ".*cookie.*/gio"{{cc|Flag g, i and o are set}}</code>
  
Available flags:
+
{| class="wikitable"
* g - global (only relevant for replace/find, missing global flag sets format_first_only flag https://en.cppreference.com/w/cpp/regex/match_flag_type and only replaces first occurence, only returns first element with regexFind)
+
|-
* i - Case insensitive
+
! Flag !! Description (short) !! Description (detailed)
* n - nosubs (https://en.cppreference.com/w/cpp/regex/syntax_option_type)
+
|-
* o - optimize (Optimize pattern, pattern creation is slower, but will execute more efficiently, https://en.cppreference.com/w/cpp/regex/syntax_option_type)
+
| g || Global || Only relevant for [[regexReplace]] and [[regexFind]]. Missing global flag sets <tt>format_first_only</tt> flag [https://en.cppreference.com/w/cpp/regex/match_flag_type (source)] and '''only replaces first occurrence''' with [[regexReplace]] and '''only returns first element''' with [[regexFind]]
 +
|-
 +
| i || Case insensitive || -
 +
|-
 +
| n || noSubs || https://en.cppreference.com/w/cpp/regex/syntax_option_type
 +
|-
 +
| o || Optimize || Optimize pattern, pattern creation is slower, but will execute more efficiently, https://en.cppreference.com/w/cpp/regex/syntax_option_type
 +
|}
  
If you don't specify any flags, the default flags are set to /gi, its valid to specify / to indicate no flags, first match only, case sensitive
+
{{Feature|Informative|If no flags are specified, the default flags are set to <tt>g</tt> and <tt>i</tt>. It is valid to specify <tt>/</tt> to indicate no flags, first match only, case sensitive.}}

Revision as of 08:43, 25 April 2021

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 /. Flags need to be lowercase. If there are any non-flag characters in the flags they will be ignored and considered part of the pattern itself. "I'm a coOkIe clicker" regexMatch ".*cookie.*/gio"// Flag g, i and o are set

Flag Description (short) Description (detailed)
g Global Only relevant for regexReplace and regexFind. Missing global flag sets format_first_only flag (source) and only replaces first occurrence with regexReplace and only returns first element with regexFind
i Case insensitive -
n noSubs https://en.cppreference.com/w/cpp/regex/syntax_option_type
o Optimize Optimize pattern, pattern creation is slower, but will execute more efficiently, https://en.cppreference.com/w/cpp/regex/syntax_option_type
If no flags are specified, the default flags are set to g and i. It is valid to specify / to indicate no flags, first match only, case sensitive.

Pages in category "Command Group: Strings - Regular Expression"

The following 3 pages are in this category, out of 3 total.