Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

Seemingly Really Obvious Expression That Eludes Me

Last post 03-26-2008, 6:43 PM by Lyndar. 9 replies.
Sort Posts: Previous Next
  •  03-26-2008, 4:05 PM 40709

    Seemingly Really Obvious Expression That Eludes Me

    I am trying to match all instances of LINES but not GRIDLINES.

    Sounds easy right?  Well apparently I'm too green to get it.  I have "Teach Yourself Regular Expressions in 10 Minutes" and was able to digest it, I have a Firefox addin named 'Regular Expressions Tester' and an app named 'Expresso' which are all very helpful, but putting this into practice seems to be a problem for me.


    My latest attempt at the expression is:

    (([^Gg][^Rr][^Ii][^Dd])|.*)([Ll][Ii][Nn][Ee][Ss])

    and it matches all of the following:

    1234lines
    gridlines
    lines
    aaaalines

    I think I can see where the problem lies - it needs to say match any number of characters and LINES except GRID and LINES but it's saying don't match GRID but do match any number of characters.


    Can someone please help me out?


    Thanks 

  •  03-26-2008, 4:33 PM 40711 in reply to 40709

    Re: Seemingly Really Obvious Expression That Eludes Me

    (?<!grid)lines

    Use this with the option for case insensitivity on.

    This basically says:

    Match the string 'lines' anywhere where it is not immediately preceded by 'grid'.

  •  03-26-2008, 4:56 PM 40712 in reply to 40711

    Re: Seemingly Really Obvious Expression That Eludes Me

    While that works in Expresso, within Visual Studio 2005 it finds no matches.  I guess it isn't supported.

    Is there another way to write this? 

  •  03-26-2008, 5:01 PM 40713 in reply to 40712

    Re: Seemingly Really Obvious Expression That Eludes Me

    Visual Studio 2005 is .NET 2.0 based.  It is the same thing that I use at work and the same thing powering Expresso.

    Please provide your actual sample text and the code you're using to do the testing and I'll take a look at it.

  •  03-26-2008, 6:05 PM 40717 in reply to 40713

    Re: Seemingly Really Obvious Expression That Eludes Me

    Thanks!

    RegEx: (?<!Grid)Lines

    Text:

    <asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" AllowPaging="True" PageSize=15 AutoGenerateColumns="False" DataSourceID="SqlDataSource1" OnPageIndexChanged="GridView1_PageIndexChanged">


    <asp:BoundColumn DataField="LineCount" HeaderText="Lines">

  •  03-26-2008, 6:27 PM 40720 in reply to 40717

    Re: Seemingly Really Obvious Expression That Eludes Me

    Are you using the .NET regex engine to do the matching in code, or are you using the regex engine that is part of the Find In Files dialog within visual studio 2005?
  •  03-26-2008, 6:30 PM 40722 in reply to 40720

    Re: Seemingly Really Obvious Expression That Eludes Me

    Find In Files - not even sure I'd know where to find the other one you mention :)
  •  03-26-2008, 6:33 PM 40723 in reply to 40722

    Re: Seemingly Really Obvious Expression That Eludes Me

    Aha, all becomes clear.  I thought you were using the .NET regex engine (System.Text.RegularExpressions namespace).

     The variety of Regex usable within visual studio is a nonstandard, greatly simplified variant.

    Try this:

    ~(grid)lines

     For the full specification of what does/doesn't work, click the 'Expression Builder' button just to the right of the 'Find What: ' text box.  Then click the 'Complete Character List' option at the bottom.

  •  03-26-2008, 6:38 PM 40724 in reply to 40723

    Re: Seemingly Really Obvious Expression That Eludes Me

    Holy moly!  Thanks for that.  How nice of MS to use different standards Hmm
  •  03-26-2008, 6:43 PM 40725 in reply to 40724

    Re: Seemingly Really Obvious Expression That Eludes Me

    Interesting, no?  From my sporadic glances through their specification, it looks like it goes back to older versions of visual studio, so it was probably a case of conflicting standards.

View as RSS news feed in XML