Regular Expression - Negate Question

What is the expresion to search for line(s) that does not contain string 20081002 ?
sepknowAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ozoCommented:
(?!.*20081002.*)
0
sepknowAuthor Commented:
Hi ozo,
Thanks.
I tried with Visual Studio 2005, UltraEdit (Perl, Unix and ultredit option), none work.
0
ghostdog74Commented:
always look for string functions in C# first. i don't know c# but itshould have IndexOf() or some substring function. Use them, its easierthan spending time creating regexp
0
HTML5 and CSS3 Fundamentals

Build a website from the ground up by first learning the fundamentals of HTML5 and CSS3, the two popular programming languages used to present content online. HTML deals with fonts, colors, graphics, and hyperlinks, while CSS describes how HTML elements are to be displayed.

ddrudikCommented:
If you want to use regex over string functions, this should work:
using System;
using System.Text.RegularExpressions;
namespace myapp
{
  class Class1
    {
      static void Main(string[] args)
        {
          String sourcestring = "your source string to match with pattern";
          Regex re = new Regex(@"^(?!.*20081002).*",RegexOptions.Multiline);
          MatchCollection mc = re.Matches(sourcestring);
          foreach (Match m in mc)
           {
                Console.WriteLine(m.Groups[0].Value);
          }
        }
    }
}

Open in new window

0
ahoffmannCommented:
> I tried with Visual Studio 2005, UltraEdit (Perl, Unix and ultredit option), none work.
Visual Studion *does not support* negative lookahead
perl *does support* it (hence you tests seem to be written wrong)
not sure for ultraedit, but I'd assume that it does not support it
"Unix" is far to vage as it has no "regex" program, if you mean awk, grep, egrep, sed, and many more (inclusing the GNU versions) , the all do not support negative lookahead

Conclusion:
  - first you need to know where you want to use your regex
  - second, most regex flavious do not support lookarround (lookahead and/or lookbehind),
    hence you cannot match "anthing except", but you need to do it programatically or change the tool (to perl for example:)
0
ghostdog74Commented:
regular expression is not always the solution, in fact it should be the last to come to mind. If the solution can be solved by plain simple string manipulation and comparison, then KISS.
0
ahoffmannCommented:
hopefully someone know how to write "KISS" in C#, Java, VB ...
*SCNR*
0
ozoCommented:
How did you try it, and what did not work?
0
ghostdog74Commented:
like i suggested, there should be a function like IndexOf() that checks where a substring exists inside a string. If OP's requirement is just simply check for string that does not contain 20081002, then something like this

if indexOf( string, substring) {
 # don't do anything as found substring.
}
0
sepknowAuthor Commented:
Hi guys, thanks for the comments.
I asked for regular expression so that I can do search/find/replace easily in UltraEdit or Visual Studio.
If these 2 software cannot support lookaround as what ahoffmann mentioned. Then I shall accept all comments and close this question.

Hi ozo,
Refer to screen shot attached.
The number of match returned was 5388 (using Perl) but actual should be 129.


UltraEdit-Find.bmp
0
ahoffmannCommented:
UE uses PCRE not perl regualr expressions, see its docs,
and as we all know: PCRE (perl compatible regular expressions) *are not* perl regular expressions
perl has full support for lookaround, PCRE has not.
So UE's GUI gives you a false sense of what you can do.

Anyway, PCRE claims to have negative lookahead, so your version of UE seems to use an old or buggy PCRE lib, IMHO.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ddrudikCommented:
The attached image is a screenshot of what for me in UE with my pattern from 22648827, the checkbox in UE called "List Lines Containing String" is apparently synonymous with the C#.NET RegexOptions.Multiline option.
UltraEdit.bmp
0
ddrudikCommented:
Thanks for the question and the points.
0
sepknowAuthor Commented:
Hi ddrudik,
yeh, it works. Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.