Regular Expression for OR Condition

Hi,

I am fetching string value(PunchTime) from document List and in loop step i am validating on branch switch(/PunchTime) then in one sequence if PunchTime is 08-02-2023T8:55:21 then output should be Present else when PunchTime is NULL output should be Absent.
I am trying to achieve using regular expression in sequence label(%PunchTime%=‘08-02-2023T8:55:21’|| %PunchTime%=‘08-02-2023T8:55:22’ || %PunchTime%=‘08-02-2023T8:55:24’) but every time in runtime flow goes to default sequence.

Could you please suggest and help with the correct regular expression for or condition to match same input string

1 Like

Hi Rishi,

please provide a screen shot of your BRANCH step showing all child sequences for further analysis.

Please check your Date/Time-Format as the hours part seems to have missing leading zeros.
Verify this against your data received, sample data will be welcome here.

Regards,
Holger

Hi Holger,

Thanks for your response. Input punch time i am fetching from csv file which i have given eg(08-02-2023T8:55:21, 08-02-2023T8:55:22) in the csv and looping over to check on punch.

Regular expression: %Punch% = ‘08-02-2023T8:55:21’ || %Punch% = ‘08-02-2023T8:55:22’ || %Punch% = ‘08-02-2023T8:55:24’
Sequence Exit on Failure.

When ever i run it always goes to first sequence however if Punch = NULL then flow should go to default sequence.

I have attached screenshot.

Hi Rishi,

in this case please share a sample snippet of the csv file as well as screenshots of FlatFile nodes definition (Dictionary, Schema, DocType).

Can you try to debug the service and provide a screen shot of generated Doc with sample data?

When the variable you are branching for is empty, there should be a sequence either labeled with $null or with condition “%Punch% == $null || %Punch% == “”” (the second means field is present, but empty (string of length 0).

Remember to use double equation marks “==” in conditions for comparison.

Regards,
Holger

AFAIK using double or single equals signs shouldn’t make any difference. I don’t think that’s the reason but there is no harm trying it out either. But comparing dates and times like a plain string can cause problems. I would recommend using pub.date:calculateDateDifference or pub.date:compareDates to compare dates, push the results to pipeline and then branch using that value. This way you will have more control and you will have better understanding on what is going wrong.

1 Like

Hi Engin,

this is the reason why I have asked for sample data and some screenshots to check this.

When thinking from a Java Development perspective, there is definitely a difference between single and double equals signs when used in conditions.
Single equals sign is an assignment, which will alter the value of the variable, while the double equals sign is the comparison.

Regards,
Holger

1 Like

As an FYI, there is no regex involved in what you’ve shared so far. Refer to the documentation for how to specify the use of regex in labels.

I’m very curious as to the scenario where specific time strings would be hard-coded in a branch – seems like something that would be changed constantly.

What “validation” are you attempting to achieve? Are you trying to confirm the layout of the string itself, that it is a proper W3C/ISO8602 string (which the format shown is not)? Are are you trying to determine if a string is simply present or not?

If you can share specifically what you’re looking to do, perhaps there may be a suggestion for that.

2 Likes

Hi Holger,

I have attached document consisting code, Dictionary, Schema, DocType. Hope that helps.

Thanks
Attendance.docx (570.4 KB)

Hi Holger,

Yes, from java point of view, there is a difference but it doesn’t matter when evaluating labels. I pushed labels to output in the results below. Using single or double equals sign doesn’t change anything, it doesn’t assign the value to the input either. Screenshots are attached.



Hi Rishi,

Imo, the way you compare the dates is not OK. First of all you are making 3 equals comparisons with dates. If you really want to compare them that way (I.E. not using date(time)compare java services) you should check the interval as %dateToCompare% > minDate & %dateToCompare% <= maxDate. Using datetime java services in a different map and using output of that service for branch will be more clean for you and for other developers in your team hence I would still recommend that.

The reason I am against comparing dates as strings (and with equals operator) is if you have more information on one side it will evaluate to false and it also checks upper/lower case and white spaces and it will fail as well if they don’t match.

2 Likes

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