simplify usage of regex for matching, replacing n-th match
----------------------------------------------------------

                 Key: CORE-4421
                 URL: http://tracker.firebirdsql.org/browse/CORE-4421
             Project: Firebird Core
          Issue Type: New Feature
            Reporter: Karol Bieniaszewski


Now we have 
similar to
substring(xxx SIMILAR 

but will be good to see simple possibility to get
- match count
- n-th match
- replace (CORE-2510)

for example we have now 4 custom udf for this

//replace all matches
function REG_REPLACE(const SDane, Pattern, Zastap: PAnsiChar): PAnsiChar; cdecl;
//replace only n-th match
function REG_REPLACE_EX(const SDane, Pattern, Zastap: PAnsiChar; Var MatchIdx: 
Integer): PAnsiChar; cdecl;
//get matches count
function REG_MATCH_COUNT(const SDane, Pattern: PAnsiChar): Integer; cdecl;
//get n-th match by "Idx"
function REG_MATCH(const SDane, Pattern: PAnsiChar; Var Idx: Integer): 
PAnsiChar; cdecl; 

and we use it like this 

UPDATE WARUNKI W SET W.WAR_GNIAZDA = cast(REG_REPLACE(REG_MATCH(W.WAR_UWAGI, 
'[0-9]+[ ]*gniazd', 0), 'gniazd', '') as Integer) WHERE W.RODZ_DZIAL_ID='RK2' 
AND REG_MATCH_COUNT(W.WAR_UWAGI, '[0-9]+[ ]*gniazd')=1;

we update records which contain only one match and we update field getting 
first match (indexed from 0) and replace non number text
of course we can do this without reg_replace only another reg_match with 
'[0-9]+' pattern but this is only sample of useage




-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://tracker.firebirdsql.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

------------------------------------------------------------------------------
Is your legacy SCM system holding you back? Join Perforce May 7 to find out:
• 3 signs your SCM is hindering your productivity
• Requirements for releasing software faster
• Expert tips and advice for migrating your SCM now
http://p.sf.net/sfu/perforce
Firebird-Devel mailing list, web interface at 
https://lists.sourceforge.net/lists/listinfo/firebird-devel

Reply via email to