#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    4
    Rep Power
    0

    Find Two Pieces of Text In Line


    Firstly, sorry for being a complete noob.

    I want to search through Xaml to find dodgily defined controls. Xaml is an Xml based markup language by Microsoft but you don't need to know anything about it. There are a couple of scenarios. The first scenario is to find all comboxes with the string ItemsSource="{Binding. So for example. I would like to search for lines like this where the highlighted items both appear in the line:

    <adaptcontrols:AdaptComboBox Name="TypeList" Grid.Column="1" Grid.Row="1" Margin="0,2,0,2" ItemsSource="{Binding ElementName=AddressTypeDef}" DisplayMemberPath="Code" SelectedItem="{Binding Path=AddressType, Mode=TwoWay}" />

    Bare in mind I am using the search functionality inside Visual Studio which supports regex. If this is a bad idea, please let me know.

    This regex finds the combobox lines, but it doesn't allow me to also search for the text ItemsSource="{Binding

    ^.*adaptcombobox.*$
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,997
    Rep Power
    9397
    The .* you have at the end mean "more stuff". So after that more stuff put the other term.
    Code:
    ^.*adaptcombobox.*itemssource="{binding.*$
    1. Probably don't need the ^ or $
    2. Probably don't need the leading and trailing .*s
    3. Might have to escape the {.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    4
    Rep Power
    0
    Thanks. I tried this, but it actually yielded no results.

    I experimented a bit more and found that this does the trick:

    ^.*(?=.*?combobox)(?=.*?itemssource="{binding).*$

    However, it is ridiculously slow in .Net. When I ran the query in EditPad it took about 20 seconds. But, in .Net it just hung for so long I had just to shut the app down. Is there any way to optimise the speed of this query?
  6. #4
  7. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,997
    Rep Power
    9397
    Drop the extra ^ $ and .*s like I mentioned, for starters. Then skip the (?= assertions.
    Code:
    combobox.*?itemssource="{binding
    should be all you need.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    4
    Rep Power
    0
    Yeah! That's looking great.

    I've changed it slightly to:

    <.*?combobox.*?itemssource="{binding.*>

    Sorry to shift the goal post, but I've just to realise that what I really need is to capture all the text from the opening "<" of the xml, right up to the closing ">".

    This is because I also need to be able to search for tags that have a piece of text, and don't have another piece of text.

    So I need to find all

    <ComboBox [...] >

    That don't have the attribute DisplayMemberPath

IMN logo majestic logo threadwatch logo seochat tools logo