ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
So far I have not been able to successfully verify that the string is not matched by any of the options in the list. Usually Google answers all my regex questions but no dice this time.
It's quite simple: you're looking for the situation where a regex, which searches for "9999" (surrounded on either side by non-digits) anywhere in the string, does not match.
Distribution: WinXP SP2 and SP3, W2K Server, Ubuntu
Posts: 313
Original Poster
Rep:
Hello Telemachos,
The reason why is that the RegEx expressions are stored in a configuration file (an SQL Server database actually). The evaluation statement is in a compiled program. By altering the configuration file (table), we can then make the statement either positive (look for a match) or negative (look where NO match) without recompiling the code. The code is not static. It is meant to handle both positive and negative statement with equal dexterity. So rather than have the negation on the IsMatch() method, we want the neagation to be in the RegEx itself.
Hope this makes sense.
We have already considered an alternative. We will add one extra column to the configuration which will indicate whether we want a match or NO match. This would allow the RegEx to always be affirmative but still allow configurable negative statements. This was a little more work and complexity though, so before going down that path, I wanted to make sure there was no way to negate string matches in RegEx. If no one on LinuxQuestions can answer, I assume I have done due diligence.
Distribution: WinXP SP2 and SP3, W2K Server, Ubuntu
Posts: 313
Original Poster
Rep:
Hello sundialsvcs,
Thanks for the reply. Unfortunately I already know that part. What I really need know is how to accomplish this. I was looking for someone to provide an example.
Distribution: WinXP SP2 and SP3, W2K Server, Ubuntu
Posts: 313
Original Poster
Rep:
Hello jan61,
Please see my above response to tele. Good idea but we want configurability outside of the compilation. We are using VB.NET as the language, although as you implied, this is not an important detail.
Distribution: WinXP SP2 and SP3, W2K Server, Ubuntu
Posts: 313
Original Poster
Rep:
Well in VB.NET it would be more like this:
If Not Regex.IsMatch("9999", port_regex_pattern) Then
'do stuff here
End If
but I see what your saying. This wont work in my case because I want the RegEx expressions stored in a configuration file and I want the RegEx to carry the negation, not the VB code. I ended up going with the workaround described above because I am satisfied that the RegEx itself cannot be negated, so I am using one extra database column to indicate negativity. If that column is TRUE then the VB statement like you described executes. Otherwise an affirmative statement executes.
In VB this looks something like:
If _
(Not match_not_found_flag AndAlso Regex.IsMatch("9999", database_regex_pattern)) _
Or _
(match_not_found_flag AndAlso Not Regex.IsMatch("9999", database_regex_pattern)) _
Then
'do stuff
End If
The real statement contains variable search_pattern and regex_pattern. I put the 9999 in just to make it more readable.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.