Sign in to follow this  
Followers 0
water

Pattern for StringRegExp that does not match

4 posts in this topic

Hi RegExp gurus,

I have a script that lets the user filter the displayed records by entering the pattern for StringRegExp. If he enters "KSE" he gets all records containing this string. What should the user enter if he wants all records but "KSE"?

Thanks in advance


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

".*(?!KSE).*"

Edited by d4ni

Share this post


Link to post
Share on other sites

".*(?!KSE).*"

Thanks for your reply.

Your example returns TRUE when the pattern isn't found in the string but unfortunately it returns TRUE as well when the pattern is found in the string.

I need a pattern for StringRegExp that only returns true when the pattern can not be found in the string

ConsoleWrite(StringRegExp("AB_IK_Leitung",".*(?!KSE).*") & @CRLF)
ConsoleWrite(StringRegExp("TM_IK_KSE_Leitung",".*(?!KSE).*") & @CRLF)

Both return TRUE but only example 1 should.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Hm strange I will look into it. I have recently looked this up myself and I thought it was that notation. I'll find the solution :mellow:!

Here you go:

$regEx = "\A(?!.*KSE).*\z"
ConsoleWrite(StringRegExp("AB_IK_Leitung", $regEx) & @CRLF)
ConsoleWrite(StringRegExp("TM_IK_KSE_Leitung", $regEx) & @CRLF)

Apparently one of the wildcards was supposed to go inside the (?!) group, and \A and \z were needed. In my script I added the \A and \z automatically to the user's RegEx, like:

Func Input($regEx)
    StringRegExp($str, "(?i)\A" & $regEx & "\z") ; (?i) for case insensitive
    ...
EndFunc

Anyway, the exclude isn't very userfriendly :( You might want to say it's "!KSE" and then form the actual Regular Expression yourself.

If you want to do that you can use this:

$r = "!KSE" ; This would be what is entered in the inputbox
$regEx = StringRegExpReplace($r, "!(.*)", "(?!.*\1).*") ; This replacement also works if the user enters !(KSE|IK) -- exclude strings which include "KSE" OR "IK"
ConsoleWrite(StringRegExp("AB_IK_Leitung", "\A" & $regEx & "\z") & @CRLF)
ConsoleWrite(StringRegExp("TM_IK_KSE_Leitung", "\A" & $regEx & "\z") & @CRLF)
Edited by d4ni

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0