Difference between revisions of "String.match"

From GiderosMobile
m (formatting)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
<languages />
 
 
'''<translate>Available since</translate>:''' Gideros 2011.6<br/>
 
'''<translate>Available since</translate>:''' Gideros 2011.6<br/>
 
'''<translate>Class</translate>:''' [[Special:MyLanguage/string|string]]<br/>
 
'''<translate>Class</translate>:''' [[Special:MyLanguage/string|string]]<br/>
=== <translate>Description</translate> ===
 
<translate>Find the first match of the regular expression "pattern" in "str", starting at position "index".
 
  
The starting position (index) is optional, and defaults to 1 (the start of the string).
+
=== Description ===
 +
Find the first match of the regular expression "pattern" in "str", starting at position "index". The starting position (index) is optional, and defaults to 1 (the start of the string).
  
If found, returns any captures in the pattern. If no captures were specified the entire matching string is returned.
+
If found, returns any captures in the pattern. If no captures were specified the entire matching string is returned. If not found, returns nil.
 +
<source lang="lua">
 +
(string) = string.match(string,pattern)
 +
</source>
 +
'''note''': this is similar to string.find, except that the starting and ending index are not returned.
  
If not found, returns nil.
+
=== Parameters ===
 +
'''string''': (String) <translate>any string</translate> <br/>
 +
'''pattern''': (String) <translate>specifies the pattern to match</translate> <br/>
  
This is similar to string.find, except that the starting and ending index are not returned.
+
=== Return values ===
 +
'''<translate>Returns</translate>''' (string) <translate>String matching pattern</translate><br/>
  
 
+
=== Example ===
print (string.match ("You see dogs and cats", "s..")) --> see</translate>
 
 
<source lang="lua">
 
<source lang="lua">
(string) = string.match(string,pattern)
+
print (string.match ("You see dogs and cats", "s..")) -- see
 
</source>
 
</source>
=== <translate>Parameters</translate> ===
 
'''string''': (String) <translate>Any string.</translate> <br/>
 
'''pattern''': (String) <translate>Specifies the pattern to match.</translate> <br/>
 
=== <translate>Return values</translate> ===
 
'''<translate>Returns</translate>''' (string) <translate>String matching pattern.</translate><br/>
 
  
 
{{String}}
 
{{String}}

Revision as of 04:14, 24 August 2020

Available since: Gideros 2011.6
Class: string

Description

Find the first match of the regular expression "pattern" in "str", starting at position "index". The starting position (index) is optional, and defaults to 1 (the start of the string).

If found, returns any captures in the pattern. If no captures were specified the entire matching string is returned. If not found, returns nil.

(string) = string.match(string,pattern)

note: this is similar to string.find, except that the starting and ending index are not returned.

Parameters

string: (String) any string
pattern: (String) specifies the pattern to match

Return values

Returns (string) String matching pattern

Example

print (string.match ("You see dogs and cats", "s..")) -- see