In the condition portion of the datamapper, for the right hand operand, is it possible to use regular expressions for value? If so, how would I go about this? Say I’m looking to match only a space (whitespace). I tried switching to javascript and using:
var re = /\s/g;
re;
Thinking this would return the regular expression re as the value to match. This didn’t work. I know I can just set the value as a space, but I’d like to know if regular expressions are supported. Thanks in advance for all help, and for pointing out any errors I may have made.
Absolutely!
I’ve attached the solution to one of the workshops in our advanced datamapper course. This example contains a switch case where each of the conditions is using a regular expression as part of the left operand. https://learn.objectiflune.com/qa-blobs/7065974556844798283.ol-datamapper
In this specific case I was using a regular expression to transform the string on the page to attempt to match it to a specific value. For example, I might have a string “NC 0300 220 0315 Mobile” but I want to match that with “NC Mobile”, so I used a regular expression to strip the numbers so that the result returned by the regular expression matches the right hand operand.
Edit: I thought I had fixed my issue by inverting, but it persists. My javascript is as follows to to pass the condition. However, the line which has nothing but space is passing. I took a screenshot of what I’m trying to have fail below. This is from a PDF source, and my goal was to use RegEx on right side of condition to match.
var re = /\S/;
re;
Thanks for your quick response, I was able to fix my issue by inverting the condition based on your example! Just out of curiosity, I’ll be coming to Montreal in June for training and will be going through the advanced datamapping course – Will you potentially be the instructor?
Cheers,
Kyle