TSO Regular Expression Testing Tool

(Originally posted 2014-04-26.)

I’ll admit I’ve found regular expressions a bit of a struggle. I bet most people have. For me it’s a matter of lots of arcane symbols that don’t have any inherent meaning. Contrast with many programming languages, which do have some.

It’s also not the case I don’t understand the concepts.

Anyhow I’m edging towards the point where Production code will need to allow regexes. So I want to take a list of space-separated names and see which items match a given regular expression.

For example a list of address space names.[1].

And so the FL (for “Filter List”) REXX EXEC was born.

The code is below. It uses grep to do the testing and BPXWUNIX invokes grep.

You invoke it with

TSO FL <regex> <list>

if you’ve put it in a suitable CLIST library. Mine is in my ISPF one. I can also call it from ISPF Option 6 or from Batch.[2]

For example


Will display the string


as these two items match the regular expression.

/* REXX */
parse arg mygrep mylist

/* Create a temporary stem set with data to pass to grep via BPXWUNIX */
do w=1 to words(mylist)

cmd='grep "'mygrep'"'

/* Do the actual grep */
call bpxwunix cmd,tmpStem.,filter.,stderr.

/* Turn returned stem set into space-separated list */
do f=1 to filter.0
  resultList=resultList filter.f

/* Print any error messages */
do e=1 to stderr.0
  say stderr.e

say strip(resultList)


Obviously this could be modified to be a callable routine, or to use one. In this simple sample I thought it best to leave it as open code.

You could probably also find a way to pass parameters to grep like -i for case insensitivity.

One further refinement which is more of a stretch is handling list items with a space in them: You’d need to rewrite the bit that creates stem variables from the words in the list string. But for my purposes I’m looking at names which don’t have spaces in them.

Observant readers will spot this code is derived from Filtering REXX Query Results With BPXWUNIX but this version is easy to prototype with from the command line.

If you’re wanting to get started with regular expressions have a play with it. Enjoy!

  1. See Towards A Pattern Explorer – Jobname Analysis where I’ve explored this before.  ↩

  2. I’ve no idea how to invoke it if the list parameter is long enough to be beyond what fits on one line – interactively. In Batch you can use + or – as a continuation character. Calling from REXX you can, of course, pass an arbitrarily long string. But for my testing a short list suffices.  ↩

Published by Martin Packer

I'm a mainframe performance guy and have been for the past 35 years. But I play with lots of other technologies as well.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

<span>%d</span> bloggers like this: