Nika-Soft logo Nika-Soft logo

PBRegexp

n_cst_re

Description

n_cst_re object represents regular expression service.

Functions

Events

The following events can be used for the purpose of localization

Examples

Demonstrates how to work with n_cst_re object
n_cst_re lnvo_re
string   ls_str = 'test (string)'
integer  li_cnt
string   ls_arr[]

lnvo_re = create n_cst_re

/*************************************************************/
/* 1.Enclose all words with brackets                         */
/*************************************************************/
ls_str = 'test (string)'
lnvo_re.of_exec(ls_str, '/\b(\w+)\b/"$1"/g')
//ls_str = '"test" ("string")'

/*************************************************************/
/* 2.Replace position of first and second word               */
/*************************************************************/
ls_str = 'first   second'
lnvo_re.of_exec(ls_str, '/\b(\w+)(\s+)(\w+)\b/$3$2$1/')
//ls_str = 'second   first'

/*************************************************************/
/* 3.Date validation                                         */
/*************************************************************/
ls_str = '11.12.2004'
if lnvo_re.of_exec(ls_str, &
   '/^ \d{1,2} ([.\/-]) \d{1,2} \1 (\d{2}|\d{4}) $/x') = 1 then
   //ok
else
   //fail
end if

/*************************************************************/
/* 4.Splits string by whitespaces                            */
/*************************************************************/
ls_str = 'first    second~tthird   ~r~n   fourth'
li_cnt = lnvo_re.of_split(ls_str, '/\s+/', ls_arr) 
/* Result: li_cnt = 4
           ls_arr[1] = 'first'
           ls_arr[2] = 'second'
           ls_arr[3] = 'third'
           ls_arr[4] = 'fourth'
*/

/*************************************************************/
/* 5.Strips C style comments from a string                   */
/*************************************************************/
ls_str = "first /*it's a comment*/ second /*comment 2*/"
lnvo_re.of_exec(ls_str, '/ \/\* .*? \*\/ //xg') 
/* Result: 'first  second ' */

destroy  lnvo_re
Copyright © NikaSoft 2004-2005