Question

Using Regex within AttributeValidator to match anything but X string

  • 7 August 2018
  • 4 replies
  • 58 views

Badge

I am sure this is a simple fix for this, but I've been testing this for hours now and going nowhere!

In AttributeValidator, I want to FAIL an attribute which contains a certain string. The most logical thing I could think of is to use the Contains Regex validation rule. Let's say I want to 'Fail' every attribute where it contains a string which = FME. I have trawled the internet and got the following expression to work within the Regex Editor:

\\b(?!FME)\\b\\S+

However, when it runs in the AttributeValidator, attributes which i have engineered to contain FME, appears from the Passed output port.

1. Is there a much simpler way within the AttributeValidator to fail any attribute which contains a certain string, rather than regex?

2. If not, am I doing something fundamentally wrong with the Regex or validation rule?

Thanks


4 replies

Userlevel 1
Badge +21

[^fme] should work for everything except fme

Edit: although it doesn't appear to....

Badge

[^fme] should work for everything except fme

Edit: although it doesn't appear to....

Thanks, @egomm that works! However, what I should have put in the question above was that there could be other string in the attribute, e.g, MEF and [^fme] would include this as well. What i need is a string only match and it looks like that is a character match?

 

Userlevel 1
Badge +21
Thanks, @egomm that works! However, what I should have put in the question above was that there could be other string in the attribute, e.g, MEF and [^fme] would include this as well. What i need is a string only match and it looks like that is a character match?

 

Try ^(?!.*fme).*$

 

 

Userlevel 2
Badge +17
Thanks, @egomm that works! However, what I should have put in the question above was that there could be other string in the attribute, e.g, MEF and [^fme] would include this as well. What i need is a string only match and it looks like that is a character match?

 

Additionally, if word boundaries are required before and after 'FME', try this one.

 

^(?!.*\bFME\b).*$

 

Reply