locked
Microsoft.VisualStudio.Text.Operations.FindData and Regular Expressions RRS feed

  • Question

  • I'm developing a VSPackage using MEF and trying to find all trailing space in the current document using ITextSearchService.FindAll, but I'm having problems with FindData's regular expressions. It doesn't seem to follow any regex rules I can figure out. It even gives me different results from the C# RegEx class.

    I've tried all variations I can think of, but it never seems to work the way I want it to. Specifically, I want the whitespace *between* the last non-whitespace character and the newline (so excluding \n and \r).

    In regular expression, \s matches whitespace, including \r and \n. So to get the trailing whitespace, you can do:

    "@"\s+$"

    ...however that will include the \n and \r characters.

    The following works everywhere else I tried it, *except* in FindData:

    @"[^\S\n\r]+$"

    ...or...

    @"\s+(?!.+\S)"

    ...etc.

    Does anyone know what expression will give me *only* the white space characters, and exclude the \n and \r characters when using FindData?

    Monday, May 12, 2014 11:46 PM

Answers

  • Yes I am using the FindOptions.UseRegularExpressions option.

    When using the same search on another .Net project that uses the .Net Regex class, I do get the right results. However FindData does not return the same results.

    I have since given up trying to get FindData to give me correct regular expression search results, and I am now doing the search by enumerating the lines and searching for the trailing spaces using a non-regular expression method.

    So this is not a problem for me anymore but I'm still curious why FindData's regular expression search doesn't seem to work properly.


    Wednesday, May 14, 2014 3:06 PM

All replies

  • Hi,

    I'm trying to involve some senior engineers into this issue and it will take some time. Your patience will be greatly appreciated.

    We will let you know if any progress is made.

    Sorry for any inconvenience.

    Best regards,

    Wednesday, May 14, 2014 2:26 AM
  • Hi,

    Please first have a double check that whether you set the FindData.FindOptions property to be FindOptions.UseRegularExpressions. If you already set search uses .NET regular expressions, you should be able to search with above regular expressions.

    Thanks.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, May 14, 2014 10:03 AM
  • Yes I am using the FindOptions.UseRegularExpressions option.

    When using the same search on another .Net project that uses the .Net Regex class, I do get the right results. However FindData does not return the same results.

    I have since given up trying to get FindData to give me correct regular expression search results, and I am now doing the search by enumerating the lines and searching for the trailing spaces using a non-regular expression method.

    So this is not a problem for me anymore but I'm still curious why FindData's regular expression search doesn't seem to work properly.


    Wednesday, May 14, 2014 3:06 PM
  • Hi,

    I temporarily closed your issue. And if you still want to resolve the FindData's regular expression search doesn't work correctly issue, please kindly share me simple demo project. You can upload it the OneDrive site, then post back the link.

    Thanks.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, May 14, 2014 10:41 PM