getGroupStart: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
m (Conversion script moved page GetGroupStart to getGroupStart: Converting page titles to lowercase)
m (Text replacement - "source>" to "syntaxhighlight>")
Line 7: Line 7:
<source lang="mtmacro" line>
<source lang="mtmacro" line>
getGroupStart(id, match, group)
getGroupStart(id, match, group)
</source>
</syntaxhighlight>
Where  
Where  
* id is the id returned by [[strfind|strfind()]]
* id is the id returned by [[strfind|strfind()]]
Line 20: 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>

Revision as of 17: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

<source lang="mtmacro" line> getGroupStart(id, match, group) </syntaxhighlight> 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

<source lang="mtmacro" line>

[h: id = strfind("this is a test", "(\\S+)\\s(\\S+)\\s*")] match 1, group 1 start = [getGroupStart(id, 1, 1)]
match 1, group 2 start = [getGroupStart(id, 1, 2)]
match 2, group 1 start = [getGroupStart(id, 2, 1)]
match 2, group 2 start = [getGroupStart(id, 2, 2)]
</syntaxhighlight> 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