How to perform a case-insensitive search by key on ISAM files
Estimated Reading Time: 1 MinutesThe START I/O statement supports the WHILE LIKE clause, which allows you to search for records that match a regular expression pattern. By leveraging regular expressions, you can greatly expand the flexibility and power of your search criteria.
In this article, we’ll demonstrate how to use the WHILE LIKE clause together with regular expressions to perform case-insensitive searches on ISAM keys. To do this:
- Begin your search pattern with
(?i)to indicate case-insensitive matching. - Enclose the word (or substring) you want to find within a dot-asterisk:
.*on both sides, so the search will locate the term in any position within the key.
For example:
Move "(?i).*salt.*" to key-search-pattern Start customers-file while key is like key-search-pattern.
The code above will allow the program to read all records (on a reading loop) that have the word "SALT" on any case combination in any position of the record key. A sample program is attached with a full example. When this sample is run, it produces the following output:
Creating file... Searching: key start Ok aKey01 aaaaaaa bKEY02 bbbbbbb ckeY03 ccccccc ----- Searching: SALT start Ok dsaLt034 ddddddd eSaLt023 eeeeeee fsaLT025 fffffff ----- Searching: raY start Ok graY002F ggggggg hRaY003G hhhhhhh iray004D iiiiiii -----