getGroup: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
No edit summary
Line 1: Line 1:
==Function getGroup==
{{MacroFunction
|name=getGroup
|description=Returns the specified capture group for the specified match that was found using [[strfind|strfind()]]


Returns the specified capture group for the specified match that was found using [[Macros:Functions:strfind|strfind()]]
|usage=
 
 
===Usage===
<source lang="mtmacro" line>
<source lang="mtmacro" line>
[h: text = getGroup(id, match, group)]
[h: text = getGroup(id, match, group)]
Line 13: Line 12:
* group is the number of the capture group found by [[Macros:Functions:strfind|strfind()]]
* group is the number of the capture group found by [[Macros:Functions:strfind|strfind()]]


===Examples===
|example=
<source lang="mtmacro" line>
<source lang="mtmacro" line>
[h: id = strfind("this is a test", "(\\S+)\\s(\\S+)\\s*")]
[h: id = strfind("this is a test", "(\\S+)\\s(\\S+)\\s*")]
Line 28: Line 27:
match 2, group 2 = test  
match 2, group 2 = test  
</pre>
</pre>
}}
[[Category:String Function]]

Revision as of 03:09, 7 March 2009

getGroup() Function

Returns the specified capture group for the specified match that was found using strfind()

Usage

[h: text = getGroup(id, match, group)]

Where

  • id is the id returned by strfind()
  • match is the number of the match found by strfind()
  • group is the number of the capture group found by strfind()

Example

[h: id = strfind("this is a test", "(\\S+)\\s(\\S+)\\s*")]
match 1, group 1 = [getGroup(id, 1, 1)]<br>
match 1, group 2 = [getGroup(id, 1, 2)]<br>
match 2, group 1 = [getGroup(id, 2, 1)]<br>
match 2, group 2 = [getGroup(id, 2, 2)]<br>

Returns

match 1, group 1 = this 
match 1, group 2 = is 
match 2, group 1 = a 
match 2, group 2 = test