PregFind: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 28: Line 28:
                 -- integer number find
                 -- integer number find
                 outputDebugString( pregFind( '123', '^-{0,1}\\d+$' ) and 'found' or 'not found' ) -- found
                 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
                 -- 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
                 outputDebugString( pregFind( 'Kenix', '^[a-zA-Z]{3,}$' ) and 'found' or 'not found' ) -- found
                 -- Russian hello ( привет ) find
                 -- Russian hello ( привет ) find
                 outputDebugString( pregFind( 'Всем привет парни, ещё раз привет :D', 'привет' ) and 'found' or 'not found' ) -- found
                 outputDebugString( pregFind( 'Всем привет парни, ещё раз привет :D', 'привет' ) and 'found' or 'not found' ) -- found

Revision as of 12:38, 25 February 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 base, string pattern )

Required Arguments

  • base: The base string for find one match.
  • pattern: The pattern for find in base string.

Returns

Returns an bool if the function was successful found one match, 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
                -- 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

Minimum server version 1.4-9.05106
Minimum client version 1.4-9.05106

Note: Using this feature requires the resource to have the above minimum version declared in the meta.xml <min_mta_version> section. e.g. <min_mta_version server="1.4-9.05106" client="1.4-9.05106" />

See Also