home   about us   contact us  
Distribtution
Financial
Appx
News
Search site for:




Regular Expressions

In one of the recent releases of APPX, support for Regular expressions was introduced. It was primarily added because it was required by the 0-apps, but we can use it in our own applications. What is a `Regular Expression'? The Wikipedia encyclopedia defines it as "A regular expression (abbreviated as regexp, regex or regxp, with plural forms regexps, regexes or regexen) is a string that describes or matches a set of strings, according to certain syntax rules. Regular expressions are used by many text editors and utilities to search and manipulate bodies of text based on certain patterns. Many programming languages support regular expressions for string manipulation." A full explanation of Regex would take more space than we have available, so we'll just give a few examples and some pointers on where you can get more information.

The Regex operators can be used in an IF, OR or AND statement, in place of the usual EQ, NE, GE, etc. You can also use them in the End User and Designer selections of Queries. There are two operators, RS and RI. RS uses case sensitive matching and RI uses case insensitive matching (tip: S-Sensitive, I-Insensitive).

A simple example: to find all names that match `Cansys', regardless of how it is capitalised, we could use a Record Selection of `RI' `cansys'. Since it is case insensitive, it will match `Cansys',`cANSYS', `CaNsYs', etc. To find all names that begin with A, F or G we would use `RS' `^(A|F|G).*'. This expression means find anything beginning with A or F or G (the `^(A|F|G)'), followed by any character (the period), followed by zero or more occurrences of the previous character (the asterisk). If we omitted the period, the asterisk would apply to the ^(A|F|G), and would mean `anything starting with zero or more occurrences of (A|F|G), which would be everything. If we left out the ^ it would mean match A, F or G anywhere in the string. If we wanted to find names regardless of upper or lower case, we would use the `RI' operator instead of the `RS' operator.

As you can see, the syntax for regular expressions can be difficult to get right. A Regular Expression with syntax errors will result in an `Overflow Error' at runtime. There are a number of different implementations of Regex - APPX uses the GNU Regex library.

For more information on Regular Expressions, try a Google search on `What is a regular expression'. They can be tricky to figure out but they can be extremely useful and it's worth the effort.



Remote Command Execution

In the Windows environment copying files from one folder to another folder on the server can be network intensive and slow if you do it from a workstation on the network. This is because the data has to be sent to your workstation, which promptly sends it back to the server. Ideally, it would be best if you could perform the copy directly on the server, however, in some situations the server is physically secured, and you don't have access to it. This tip shows a technique that allows you to enter commands on your workstation that are executed directly on the server.



Removing Records from a Constrained Scrolling Display

We have found that you can remove a record from a scrolling, constrained display when it no longer meets the constraint by performing a READ with HOLD on the record, and setting OPTION to NEXT RECORD in the option intercept event point. For example, if you have list of Orders constrained by Order Status displayed, and you allow the operator to change the status via an Option key that you intercept yourself, it would be nice if APPX would make the record disappear from the display once your code changes the Order Status, since it no longer meets the constraint. The usual method is to end the process and reinvoke it, causing APPX to refresh the display. There are 2 problems with this, the display starts from the beginning of the file, causing the operator to manually find their position, and it gets complicated if your Input process is invoked from more than one place with different constraints or default keys (you have to keep track of where you came from so you know how to reinvoke the process). By setting Option to NEXT RECORD, APPX will reread the records surrounding the one it was on, and discard the one that doesn't meet the constraint. Presto, the record disappears!

Note that if you issue an ERROR, WARNING or even a MESSAGE command at the same time as you set OPTION = NEXT RECORD, this will not work.


Do you have a tip you want to pass on? Contact Us.


« Return



© Copyright 2009 - C.A.N.S.Y.S. West Limited All Rights Reserved