PregFind: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
m (→‎Syntax: Grammar?!)
Line 7: Line 7:
==Syntax==
==Syntax==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
bool pregFind ( string base, string pattern )
bool pregFind ( string subject, string pattern )
</syntaxhighlight>
</syntaxhighlight>


===Required Arguments===
===Required Arguments===
*'''base:''' The base [[string]] for find one match.
*'''subject:''' The input [[string]]
*'''pattern:''' The pattern for find in base string.
*'''pattern:''' The pattern [[string]] to search for in the input [[string]].


===Returns===
===Returns===
Returns an ''[[bool]]'' if the function was successful found one match, ''false'' otherwise.
Returns ''true'' if the pattern was found in the input string, ''false'' otherwise.


==Example==  
==Example==  

Revision as of 10:40, 6 June 2013

ADDED/UPDATED IN VERSION 1.4 r5106:

This function find only one match and when match is founded stop working and return a result.

Syntax

bool pregFind ( string subject, string pattern )

Required Arguments

Returns

Returns true if the pattern was found in the input string, false otherwise.

Example

Click to collapse [-]
Shared ( client and server )

Some examples:

addCommandHandler( 'examples',
	function( )
                -- hello word find
		outputDebugString( pregFind( 'hello world, hello world, hello world', 'hello world' ) and 'found' or 'not found' ) -- found 
                -- integer number find
                outputDebugString( pregFind( '123', '^-{0,1}\\d+$' ) and 'found' or 'not found' ) -- found
                -- Login with a-z and A-Z symbols and have more 3 symbols and without any spaces
                outputDebugString( pregFind( 'Kenix', '^[a-zA-Z]{3,}$' ) and 'found' or 'not found' ) -- found
                -- RP nickname check
                outputDebugString( pregFind( 'Garry_Newman', '([A-Z]{1,1})[a-z]{2,9}_([A-Z]{1,1})[a-z]{2,9}' ) and 'found' or 'not found' ) -- found
                -- Russian hello ( привет ) find
                outputDebugString( pregFind( 'Всем привет парни, ещё раз привет :D', 'привет' ) and 'found' or 'not found' ) -- found
                -- Sequence of numbers
                outputDebugString( pregFind( '5, 10', '^([1-9]{1}[0-9]{0,})+(((,\s|,)[1-9]{1}[0-9]{0,}){0,1}){1,1}' ) and 'found' or 'not found' ) -- found
	end
)

Requirements

This template will be deleted.

See Also