Regex Help

I have a paint layout that displays some image assets. Each image has a select metadata that can either be Yes or No. I am trying to set up a regex conditional keyword to print content only if the image metadata field is set to Yes. But, every regex I try just returns true each time.


Here is what I am using:


    m/Yes/


Does anyone know if this syntax is correct to check if my metadata select field has the string, Yes? Currently it does not work how I want...

[quote]I have a paint layout that displays some image assets. Each image has a select metadata that can either be Yes or No. I am trying to set up a regex conditional keyword to print content only if the image metadata field is set to Yes. But, every regex I try just returns true each time.


Here is what I am using:

    m/Yes/


Does anyone know if this syntax is correct to check if my metadata select field has the string, Yes? Currently it does not work how I want...[/quote]

Perhaps try with the beginning and end delimiters as given below:
    ^Yes$

[quote]Perhaps try with the beginning and end delimiters as given below:

    ^Yes$
[/quote]

I had tried that before, and it still does not work. So, I assume if the string is found, the regex returns true?

Normally I just check to see if a field is empty using ^$ and it works great, but strangely, when searching for a string within a metadata field it is giving me issues.

Just tried:

    m/^Yes$/i


No luck.

Well, I ended up using javascript instead of the conditional keywords to get this working.


But I still find it strange that the regex didn't work. Has anyone at Squiz every actually used a text string comparison in a conditional statement? I am just curious is this might be a bug.

I've had it working a few times. If you just want to match on the word "Yes", just include that word. You should need anything else.

[quote]Well, I ended up using javascript instead of the conditional keywords to get this working.


But I still find it strange that the regex didn't work. Has anyone at Squiz every actually used a text string comparison in a conditional statement? I am just curious is this might be a bug.[/quote]



It does work, we do use it. Maybe you have hit a bug - you could file a bug report with full details of exactly what your comparison is ad how to reproduce it.



Does any other regexp work? Which version are you on? I do remember a bug fix a while back for some regexps - you could search the bug tracker if you are not on the latest release of the branch you are on.

[quote]It does work, we do use it. Maybe you have hit a bug - you could file a bug report with full details of exactly what your comparison is ad how to reproduce it.


Does any other regexp work? Which version are you on? I do remember a bug fix a while back for some regexps - you could search the bug tracker if you are not on the latest release of the branch you are on.[/quote]



Justin, do you know the expression that you use?



I want to test it a bit more before submitting a but. It does work for things like finding if a field is empty using ^$, which I use all the time.



I am using this on a 3.20.1 system.

[quote]I had tried that before, and it still does not work. So, I assume if the string is found, the regex returns true?


Normally I just check to see if a field is empty using ^$ and it works great, but strangely, when searching for a string within a metadata field it is giving me issues.



Just tried:


    m/^Yes$/i


No luck.[/quote]

Matrix already includes the start and end expression characters, as well as the "i" for case insensitivity. That's why it works with just "Yes" as the regex.

The ^ and the $ are overkill anyway, because you know the options will either be "Yes" or "No". Those extra characters are only of use if you were matching on something like "NoYesNo" and you didn't want it to match.

If you really want to use them, I would expect this to match "Yes":

    ^Yes$


If that doesn't work, submit a bug.