getGroupStart: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
(New page: ==Function getGroupEnd== {{ProposedChange}} Returns the start index of the specified capture group for the specified match that was found using strfind() ==...)
 
m (Text replacement - "<source" to "<syntaxhighlight")
 
(10 intermediate revisions by 4 users not shown)
Line 1: Line 1:
==Function getGroupEnd==
{{MacroFunction
{{ProposedChange}}
|name=getGroupStart
|version=1.3b48
|description=Returns the start index of the specified capture group for the specified match that was found using [[strfind|strfind()]]


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


===Examples===
|example=
<source lang="mtmacro" line>
<syntaxhighlight 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*")]
match 1, group 1 start = [getGroupStart(id, 1, 1)]<br>
match 1, group 1 start = [getGroupStart(id, 1, 1)]<br>
Line 21: Line 20:
match 2, group 1 start = [getGroupStart(id, 2, 1)]<br>
match 2, group 1 start = [getGroupStart(id, 2, 1)]<br>
match 2, group 2 start = [getGroupStart(id, 2, 2)]<br>
match 2, group 2 start = [getGroupStart(id, 2, 2)]<br>
</source>
</syntaxhighlight>
Returns
Returns
<pre>
<pre>
Line 29: Line 28:
match 2, group 2 start = 10  
match 2, group 2 start = 10  
</pre>
</pre>
}}
[[Category:String Function]]

Latest revision as of 23:59, 14 March 2023

getGroupStart() Function

Introduced in version 1.3b48
Returns the start index of the specified capture group for the specified match that was found using strfind()

Usage

getGroupStart(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 start = [getGroupStart(id, 1, 1)]<br>
match 1, group 2 start = [getGroupStart(id, 1, 2)]<br>
match 2, group 1 start = [getGroupStart(id, 2, 1)]<br>
match 2, group 2 start = [getGroupStart(id, 2, 2)]<br>

Returns

match 1, group 1 start = 0 
match 1, group 2 start = 5 
match 2, group 1 start = 8 
match 2, group 2 start = 10