Difference between revisions of "regexFind"

From Bohemia Interactive Community
Jump to navigation Jump to search
(Article creation)
 
m (Fixed "regex pattern" link)
(11 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
{{RV|type=command
 
{{RV|type=command
  
|game1= arma3dev
+
|game1= arma3
 +
|version1= 2.06
  
|version1= 2.05
+
|descr= Returns all all matches found with given ''pattern'' in given ''haystack'' and their offset.
  
|descr= Offsets are relative to haystack start, ignoring the provided startOffset.
+
|gr1= Strings - Regular Expression
startOffset being <0 or >= count hayStack will trigger a script error and return empty array
 
  
|gr1= regex
+
|s1= haystack [[{{PAGENAMEE}}]] [pattern, startOffset]
  
|s1= haystack [[{{PAGENAMEE}}]] [pattern, (startOffset)]
+
|p1= haystack: [[String]]
  
|r1= [[match1, offset1], [match2, offset2], ... [matchN, offsetN]]
+
|p2= pattern: [[String]] - Format [[Arma 3: Regular Expressions|regex pattern]]
 
 
|p1= haystack: [[String]]
 
  
|p2= pattern: [[String]] - Format [[:Category:Command Group: regex|regex pattern]]
+
|p3= offset: [[Number]] - (Optional, default: 0) has to be in range from 0 to {{ic|[[count]] ''haystack''}} (''haystack length'')
  
|p3= offset: [[Number]] - (Optional) default: 0, must be count haystack < offset >= 0
+
|r1= [[Array]] of nested arrays. Each lowest level array in format:
 +
* 0: [[String]] - Match
 +
* 1: [[Number]] - Offset of given match relative to ''haystack'' beginning. Provided ''offset'' is ignored
  
|x1= <code>"wooKie boOkie cookie" [[{{PAGENAMEE}}]] [".ookie/gio"] {{cc|<nowiki>[["wooKie",0],["boOkie",7],["cookie",14]]</nowiki>}}</code>
+
|x1= <code>"wooKie boOkie cookie" [[{{PAGENAMEE}}]] [".ookie/gio"]; {{cc|<nowiki>[[["wooKie",0]],[["boOkie",7]],[["cookie",14]]]</nowiki>}}</code>
  
|x2= <code>"wooKie boOkie cookie" [[{{PAGENAMEE}}]] [".ookie/i"] {{cc|<nowiki>[["wooKie",0]]</nowiki>}}</code>
+
|x2= <code>"wooKie boOkie cookie" [[{{PAGENAMEE}}]] [".ookie/i"]; {{cc|<nowiki>[[["wooKie",0]]]</nowiki>}}</code>
  
|x3= <code>"wooKie boOkie cookie" [[{{PAGENAMEE}}]] [".ookie/"] {{cc|<nowiki>[["wooKie",0],["boOkie",7],["cookie",14]]</nowiki>}}</code>
+
|x3= <code>"wooKie boOkie cookie" [[{{PAGENAMEE}}]] [".ookie/"]; {{cc|<nowiki>[[["cookie",14]]]</nowiki>}}</code>
  
 
|x4= Multiline example:<code>"co1kie2
 
|x4= Multiline example:<code>"co1kie2
co2kie" [[{{PAGENAMEE}}]] ["^co.kie$"] {{cc|<nowiki>[["co1kie",0],["co2kie",8]]</nowiki>}}</code>
+
co2kie" [[{{PAGENAMEE}}]] ["^co.kie$"]; {{cc|<nowiki>[[["co2kie",9]]]</nowiki>}}</code>
  
|x5= <code>"I'm a cookie clicker" [[{{PAGENAMEE}}]] ["c(.*?)k(.*?)e/i"] {{cc|<nowiki>[["cookie",6],["oo",7],["i",10]]</nowiki>}}</code>
+
|x5= <code>"I'm a cookie clicker" [[{{PAGENAMEE}}]] ["c(.*?)k(.*?)e/i"]; {{cc|<nowiki>[[["cookie",6],["oo",7],["i",10]]]</nowiki>}}</code>
  
|x6= <code>"I'm a cookie clicker" [[{{PAGENAMEE}}]] ["c(.*?)k(.*?)e"] {{cc|<nowiki>[["cookie",6],["oo",7],["i",10],["clicke",13],["lic",14],["",18]]</nowiki>}}</code>
+
|x6= <code>"I'm a cookie clicker" [[{{PAGENAMEE}}]] ["c(.*?)k(.*?)e"]; {{cc|<nowiki>[[["cookie",6],["oo",7],["i",10]],[["clicke",13],["lic",14],["",18]]]</nowiki>}}</code>
  
 
|seealso= [[regexMatch]] [[regexReplace]]
 
|seealso= [[regexMatch]] [[regexReplace]]
 
}}
 
}}

Revision as of 19:43, 5 October 2021

Hover & click on the images for description

Description

Description:
Returns all all matches found with given pattern in given haystack and their offset.
Groups:
Strings - Regular Expression

Syntax

Syntax:
haystack regexFind [pattern, startOffset]
Parameters:
haystack: String
pattern: String - Format regex pattern
offset: Number - (Optional, default: 0) has to be in range from 0 to count haystack (haystack length)
Return Value:
Array of nested arrays. Each lowest level array in format:
  • 0: String - Match
  • 1: Number - Offset of given match relative to haystack beginning. Provided offset is ignored

Examples

Example 1:
"wooKie boOkie cookie" regexFind [".ookie/gio"]; // [[["wooKie",0]],[["boOkie",7]],[["cookie",14]]]
Example 2:
"wooKie boOkie cookie" regexFind [".ookie/i"]; // [[["wooKie",0]]]
Example 3:
"wooKie boOkie cookie" regexFind [".ookie/"]; // [[["cookie",14]]]
Example 4:
Multiline example:"co1kie2 co2kie" regexFind ["^co.kie$"]; // [[["co2kie",9]]]
Example 5:
"I'm a cookie clicker" regexFind ["c(.*?)k(.*?)e/i"]; // [[["cookie",6],["oo",7],["i",10]]]
Example 6:
"I'm a cookie clicker" regexFind ["c(.*?)k(.*?)e"]; // [[["cookie",6],["oo",7],["i",10]],[["clicke",13],["lic",14],["",18]]]

Additional Information

See also:
regexMatch regexReplace

Notes

Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note