MiniM Overview |
MiniM
Knowledge Base | Jul 26, 2011 Useful Regular Expressions Regular expressions are much power and significant and may be counted as one more programming language. Regular expressions may be much useful in application servers which check user unput, inputs data from external data sources and in many user-frienfly tasks. MUMPS language does not contain builtin regular expressions. Nearest to regular expressiona are MUMPS patterns. To extent possibilities of application servers based on the MiniM Database Server there was implemented some system functions:
Prefix PCRE means Perl Compatible Regular Expressions. This functions are built on the pcre library. Here are some of the benefits of regular expressions. In many cases, programmers are also treated to a special libraries of regular expressions. In most cases they all may be used in MiniM with regards to syntax and $ZPCREXXX functions arguments meaning. Remove leading whitespaces USER>s str=" abc def " USER>s regexp="^\s+" USER>w """",$zpcrer(str,regexp,""),"""" "abc def " Note that the \s symbol means not only whitespace, it also includes tabstop, new line, form feed and carriage return symbols. Remove trailing whitespaces USER>s str=" abc def " USER>s regexp="\s+$" USER>w """",$zpcrer(str,regexp,""),"""" " abc def" Remove leading and trailing whitespaces USER>s str=" abc def " USER>s regexp="^\s+|\s+$" USER>w """",$zpcrer(str,regexp,"","g"),"""" "abc def" Remove repeatable whitespaces between words except leading and trailing ones USER>s str=" abc def " USER>s regexp="(\w)( )+(\w)" USER>w """",$zpcrer(str,regexp,"$1 $3","gp"),"""" " abc def " Replace repeatable whitespaces to single and remove leading and trailing whitespaces USER>s str=" abc def " USER>s regexp="^\s+|(?<=\s)( )+|\s+$" USER>w """",$zpcrer(str,regexp,"","g"),"""" "abc def" Remove all non-alpha symbols from begin of the string USER>s str=" abc def " USER>s regexp="^([[:^alpha:]])+" USER>w """",$zpcrer(str,regexp,""),"""" "abc def " Get list of all number sequences USER>s str=" 123 789.as456ee333" USER>s regexp="\d+" USER>s found=$zpcres(str,regexp,"g") USER>f i=1:1:$ll(found) w $lg(found,i),! 123 789 456 333 Simple IPv4 address matching USER>s regexp="^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$" USER>w $zpcrem("127.0.0.1",regexp),! 1 USER>w $zpcrem("222.333.444.555",regexp),! 1 Full IPv4 address matching USER>s r="^(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}$" USER>w $zpcrem("127.0.0.1",r),! 1 USER>w $zpcrem("222.333.444.555",r),! 0Eugene Karataev support@minimdb.com
|
|
Info Support |