Regular expression for numbers in webMethods 10 is not working

webMethods10.7

I’m trying to generate an email template using the variables. Im using %ifvar% constructor… My sample code is;

%ifvar isFuture equals(‘1’)%
%ifvar dayGap matches(‘/([0-9]|[1-9][0-9]|[1-9][0-9][0-9])/’)%

%value info/subj%
%value info/valid%
%value info/is%

                </TR>
                %else%
                <TR valign="top" bgcolor= #eeeeee >
                <TD>%value info/subj%</TD>  
                <TD>%value info/valid%</TD>  
                <TD>%value info/is%</TD>  
                
                </TR>
                %endifvar%

%else%

im trying to match the “dayGap” variable to 1-1000 numbers. But it is not working… May I know what is wrong here? does webMethods support reg ex for numbers?

p.s: I tried the following combinations too

  • %ifvar dayGap matches(‘^([0-9]|[1-9][0-9]|[1-9][0-9][0-9])$’)%
  • %ifvar dayGap matches(‘([0-9]|[1-9][0-9]|[1-9][0-9][0-9])’)%

The / / that surround the regex are not needed in this context. Those are for step labels to indicate a regex is being used.

An alternative to consider:

^(?:0|[1-9]\d{0,2})$

Hi Reamon; Thanks for the help…SO I changed the template like;

%ifvar dayGap matches(‘^(?:0|[1-9]\d{0,2})$’)%

%value trustS%

But it didnt work…
May I know waht is the number range it checks with below regex.?

^(?:0|[1-9]\d{0,2})$’

0 through 999

^ - anchor to the beginning of the string
(?: - non-capturing version of parentheses
0 - match zero
| - or
[1-9] - digits 1 through 9
\d - any digit
(0,2) - 0, 1, 2 repeat of previous
$ - anchor to end of the string

Have you confirmed dayGap is present and has a value? (Equivalent of “is it plugged in” but I gotta ask :slight_smile: )

4 Likes

Hi raemon;
Thanks… Yes daygap is present…

%ifvar dayGap matches (‘^(?:0|[1-9]\d{0,2})$’)%

%value trustS% ....
</TR>

%else%

%value trustS%

I always get at else block whenever my daygap values changes to 1-3000

Forgive me but I do not see evidence that dayGap has a value, or what value it has. Do you have screen shot or something that shows its value?

1 Like

I assume daysRemaining (previously dayGap?) is a child element within sortedCerts? Possible scoping issue.

Can you share the doc list structure screen shot? Perhaps the Results tab showing the pipeline of the service once it has obtained its list of sortedCerts. Still don’t see evidence that daysRemaining is populated but I guess I’ll trust that you see 35, 215, etc.

Might I suggest a possible simplification of the DSP. No need to repeat all the <TD> tags for all the fields. Use the ifvar to “write” the <TR> as desired (with or without highlight) followed by one set of the fields.

%ifvar daysRemaining matches ('^(?:0|[1-9]\d{0,2})$')%
  <TR valign="top" bgcolor=#FFDB00>
%else%
  <TR valign="top" bgcolor=#eeeeee>
%endif%

  <TD>%value trustStoreAlias%</TD>
  <TD>%value keystore% %value keyAlias%</TD>
  ...
</TR>
1 Like

I’m not attempting to answer the original question, but just want to recommend online regex testing services like https://regex101.com/ – they are a great way to test, validate and understand regexs.

Thanks for that tutorial link and I tried this

^(?:0|[1-9]\d{0,1})$

Regular expression which matches the numbers between 1-100…So I expect my row colour should change but it is not working as expected…
That is what im looking for help here…

@Ratha_v - ana, here’s another, possibly simpler, regex:
^\d{1,2}$|^100$

^\d{1,2}$ matches one or two digits and covers 0-99. The ^100$ just checks for ‘100’.

I tested the regex above and saved the regex query here. The blue highlights shows how the regex matches numbers from 0 to 100, but does not match other numbers or values.
image.

But try avoiding regexs when possible. For instance, you could calculate a cert_alert variable (true/false) in your Flow code and change the DSP background based on its value.

Personally, regexs intimidate me somewhat. :smiley: There’s this famous saying: :smiley:

Some people, when confronted with a problem, think “I know, I’ll use regular expressions.” Now they have two problems.

2 Likes

I went with the variable option as you said…and its working charmly than regex…

Glad to hear it ana! :smiley: It’s more maintainable than regular expressions.

webMethods really should make %ifvar% support math operations like >=, <, etc

Debatable, but I do understand the concern about regex. Easy to get them wrong. As with many computing topics, takes time to understand and get comfortable with them. :slight_smile:

It is likely that “regular expression” in the DSP context is not regular expressions at all. Found this from years ago:DSP regular expressions (ifvar matches)

“It just uses * and ? as kind of wild card.”

This is from Xiaowei Wang back in 2015. In that thread he indicates he patched it to make it support regex – but that would apply to his own installation.

So mystery solved I think – ifvar matches support wildcards, not regex. Even the example in the help doc for ifvar implies this:

For example: %ifvar carrier matches(‘UPS*’)%.

If that were regex, it would match strings starting with UP followed by 0 or more S chars. Unlikely to be useful. A regex for this would be ‘UPS.*’

Documentation bug IMO. And would be nice if in addition to the math operators it would support regex (and maybe wildcards).

1 Like

Very true. I should have clarified my comment was specific to using regexs with %ifvar% – a match not made in heaven.

Very nice work Rob! That makes sense.

I was just musing this wildcard-based construct may work for matching 0-100 days (assuming ‘?’ matches one digit).

%ifvar var matches('?')%
   ...DO STUFF...
%else%
%ifvar var matches('??')%
   ...DO STUFF...
%else%
%ifvar var matches('100')%
   ...DO STUFF...

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.