regex use in Websphere MQ

544 Views Asked by At

As I am new to regex, can anyone give me the detailed explanation of the following regex:-

ZBC_EXTR[0-9]{0,1}\_STOCK_([A-Z]{0,1}|[0-9]{0,1})
1

There are 1 best solutions below

0
javaBean007 On

This is regex is looking for a string with various parts to it.

"ZBC_EXTR" - The string must begin with these characters
"[0-9]{0,1}" - Looks for a digit 0-9, can appear 0 times but not more than once
"\" - Escape character(Escapes the following character for regex engine) 
"_STOCK_" - Must have these set of characters next
"(" - Beginning of the group expression
"[A-Z]{0,1}" - Look for alpha, capital character,can appear 0 times but not more than once
"|" - The logic OR expression
"[0-9]{0,1}" - Looks for a digit 0-9, can appear 0 times but not more than once
")" - End of the group expression

For example the following strings would match the regex expression:

ZBC_EXTR8_STOCK_
ZBC_EXTR_STOCK_
ZBC_EXTR_STOCK_F

But these strings would NOT match:

ZBC_EXTR_STOCKF
ZBC_EXTRA_STOCK_F
ZBC_EXTR45_STOCK

A good resource for regex: https://www.regular-expressions.info/