Jump to content

Pattern for StringRegExp that does not match


water
 Share

Recommended Posts

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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...