Find & Replace Question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • inpuarg

    Find & Replace Question

    I want to find a & character using Regex. But not &&
    How can i manage this in c# Quickfind window ?
    --------------------------------------------------
    ne kadar yaþarsan yaþa
    sevdiðin kadardýr ömrün :(
    --------------------------------------------------
  • Dave Sexton

    #2
    Re: Find & Replace Question

    Hi,

    Then just use a single "&".

    "&" isn't a special character in Regular Expressions.

    --
    Dave Sexton

    "inpuarg" <inpuarg@wherel and.comwrote in message
    news:6ri2n2d11u 5u6j21973dofvni 5miudh539@4ax.c om...
    >I want to find a & character using Regex. But not &&
    How can i manage this in c# Quickfind window ?
    --------------------------------------------------
    ne kadar yaþarsan yaþa
    sevdiðin kadardýr ömrün :(
    --------------------------------------------------

    Comment

    • inpuarg

      #3
      Re: Find &amp; Replace Question

      ok. ut the problem is , when i 've searched for & character it finds
      me every && chatacters also. and i 'm not interested in with this.
      There are millions of in logical operations. i 'm interested in with
      single & .



      On Sat, 2 Dec 2006 06:40:06 -0500, "Dave Sexton"
      <dave@jwa[remove.this]online.comwrote :
      >Hi,
      >
      >Then just use a single "&".
      >
      >"&" isn't a special character in Regular Expressions.
      --------------------------------------------------
      ne kadar yaþarsan yaþa
      sevdiðin kadardýr ömrün :(
      --------------------------------------------------

      Comment

      • Dave Sexton

        #4
        Re: Find &amp; Replace Question

        Hi,

        Sorry - I misunderstood.

        I don't think that's possible though. There doesn't appear to be any
        negative look-ahead assertion in VS 2005's version of Regex:

        "Regular Expressions (Visual Studio)"


        --
        Dave Sexton

        "inpuarg" <inpuarg@wherel and.comwrote in message
        news:iup2n21sog eh5a37f0o7q59vj cujnq8uvo@4ax.c om...
        ok. ut the problem is , when i 've searched for & character it finds
        me every && chatacters also. and i 'm not interested in with this.
        There are millions of in logical operations. i 'm interested in with
        single & .
        >
        >
        >
        On Sat, 2 Dec 2006 06:40:06 -0500, "Dave Sexton"
        <dave@jwa[remove.this]online.comwrote :
        >
        >>Hi,
        >>
        >>Then just use a single "&".
        >>
        >>"&" isn't a special character in Regular Expressions.
        --------------------------------------------------
        ne kadar yaþarsan yaþa
        sevdiðin kadardýr ömrün :(
        --------------------------------------------------

        Comment

        • Lee

          #5
          Re: Find &amp; Replace Question

          The following untested RegExp might work:

          [~&]&[~&]

          It should find an & that is neither preceded nor followed by an &.

          --
          // Lee Silver
          // Information Concepts Inc.

          inpuarg wrote:
          I want to find a & character using Regex. But not &&
          How can i manage this in c# Quickfind window ?
          --------------------------------------------------
          ne kadar yaþarsan yaþa
          sevdiðin kadardýr ömrün :(
          --------------------------------------------------

          Comment

          • Dave Sexton

            #6
            Re: Find &amp; Replace Question

            Hi Lee,

            Good idea (incorrect syntax though). Based off that pattern I got this to
            work:

            &~([&:b])

            However, it will match the last "&" in "&&" when it's not immediately
            followed by a space or tab. In other words, the pattern matches "&", and
            the last "&" in "&&", but not, "&& ".

            I thought it might be acceptable since it's common for && to be followed by
            at least one space in code. If you can't guarantee that, then the pattern
            will not work for you.

            Just FYI,

            [^&]&[^&] and ~(&)&~(&)

            didn't work for me, unfortunately.

            HTH

            --
            Dave Sexton

            "Lee" <lsilver@inform ation-concepts.comwro te in message
            news:1165075827 .716564.276240@ 16g2000cwy.goog legroups.com...
            The following untested RegExp might work:

            [~&]&[~&]

            It should find an & that is neither preceded nor followed by an &.

            --
            // Lee Silver
            // Information Concepts Inc.

            inpuarg wrote:
            I want to find a & character using Regex. But not &&
            How can i manage this in c# Quickfind window ?
            --------------------------------------------------
            ne kadar yaþarsan yaþa
            sevdiðin kadardýr ömrün :(
            --------------------------------------------------

            Comment

            • Lee

              #7
              Re: Find &amp; Replace Question

              Dave:

              Yeah, on the syntax, ~ should have been ^ -- that's what I get for
              posting un-tested code.

              OTOH, I just tried [^&]&[^&] and it works as advertised -- it finds &'s
              that are not also &&'s. This works in VS 2005; but I don't know about
              VS2003.

              Based on what the OP wanted, I would probably modify the RE to
              [^&]&[^=&] in order to bypass the &= operator.

              --
              // Lee Silver
              // Information Concepts Inc.


              Dave Sexton wrote:
              Hi Lee,
              >
              Good idea (incorrect syntax though). Based off that pattern I got this to
              work:
              >
              &~([&:b])
              >
              However, it will match the last "&" in "&&" when it's not immediately
              followed by a space or tab. In other words, the pattern matches "&", and
              the last "&" in "&&", but not, "&& ".
              >
              I thought it might be acceptable since it's common for && to be followed by
              at least one space in code. If you can't guarantee that, then the pattern
              will not work for you.
              >
              Just FYI,
              >
              [^&]&[^&] and ~(&)&~(&)
              >
              didn't work for me, unfortunately.
              >
              HTH
              >
              --
              Dave Sexton
              >
              "Lee" <lsilver@inform ation-concepts.comwro te in message
              news:1165075827 .716564.276240@ 16g2000cwy.goog legroups.com...
              The following untested RegExp might work:
              >
              [~&]&[~&]
              >
              It should find an & that is neither preceded nor followed by an &.
              >
              --
              // Lee Silver
              // Information Concepts Inc.
              >
              inpuarg wrote:
              I want to find a & character using Regex. But not &&
              How can i manage this in c# Quickfind window ?
              --------------------------------------------------
              ne kadar yaþarsan yaþa
              sevdiðin kadardýr ömrün :(
              --------------------------------------------------

              Comment

              • Dave Sexton

                #8
                Re: Find &amp; Replace Question

                Hi Lee,

                I'm suprised that works for you. I'm using VS 2005 as well and it doesn't
                work for me. Actually, both of the examples that didn't work for me matched
                absolutely nothing at all - not even a single "&".

                I just tested it again. When I tested it the first time I just typed &'s
                and &&'s (and some with trailing spaces) along the left margin of an empty
                document, one per line. Apparently, [^&]&[^&] only works if there is some
                combination of characters before the "&", even if it's whitespace, but it
                doesn't just match "&" it makes the whitespace around it as well.

                So, for instance, the resulting match would be " & ", not "&".

                Also, it's kinda buggy. If I enter "&" along the left margin it doesn't
                match. Then, if I insert whitespace before it, other than &'s, it still
                doesn't match! I have to delete it and enter some strange combination of
                tabs, spaces and characters before it first, then type &, and then it will
                match. But even that doesn't work every time, although it seems to find " &
                " in "if ((0 & 1) == 0)" with no problem :)

                --
                Dave Sexton

                "Lee" <lsilver@inform ation-concepts.comwro te in message
                news:1165085806 .761965.163910@ j72g2000cwa.goo glegroups.com.. .
                Dave:

                Yeah, on the syntax, ~ should have been ^ -- that's what I get for
                posting un-tested code.

                OTOH, I just tried [^&]&[^&] and it works as advertised -- it finds &'s
                that are not also &&'s. This works in VS 2005; but I don't know about
                VS2003.

                Based on what the OP wanted, I would probably modify the RE to
                [^&]&[^=&] in order to bypass the &= operator.

                --
                // Lee Silver
                // Information Concepts Inc.


                Dave Sexton wrote:
                Hi Lee,
                >
                Good idea (incorrect syntax though). Based off that pattern I got this to
                work:
                >
                &~([&:b])
                >
                However, it will match the last "&" in "&&" when it's not immediately
                followed by a space or tab. In other words, the pattern matches "&", and
                the last "&" in "&&", but not, "&& ".
                >
                I thought it might be acceptable since it's common for && to be followed
                by
                at least one space in code. If you can't guarantee that, then the pattern
                will not work for you.
                >
                Just FYI,
                >
                [^&]&[^&] and ~(&)&~(&)
                >
                didn't work for me, unfortunately.
                >
                HTH
                >
                --
                Dave Sexton
                >
                "Lee" <lsilver@inform ation-concepts.comwro te in message
                news:1165075827 .716564.276240@ 16g2000cwy.goog legroups.com...
                The following untested RegExp might work:
                >
                [~&]&[~&]
                >
                It should find an & that is neither preceded nor followed by an &.
                >
                --
                // Lee Silver
                // Information Concepts Inc.
                >
                inpuarg wrote:
                I want to find a & character using Regex. But not &&
                How can i manage this in c# Quickfind window ?
                --------------------------------------------------
                ne kadar yaþarsan yaþa
                sevdiðin kadardýr ömrün :(
                --------------------------------------------------

                Comment

                • Lee

                  #9
                  Re: Find &amp; Replace Question

                  Dave:

                  My RE will not find a single & that is in the left or right margin --
                  but in dealing with realistically entered code, the chances of one in
                  the left margin I think are nil; and as the right-most character only
                  marginally bigger.

                  I haven't tried it, but I don't see why it wouldn't match the string "
                  & " -- it should match any & preceded and followed by a non-&. OTOH, as
                  you say, the match will hi-light 3 characters because the RE matches 3
                  characters. For just doing a search, hi-lighting 3 characters should
                  not be a problem; and even if doing a Replace, specifying \1 and \2 in
                  the replacment string (and enclosing each [^&] in the RE in braces
                  thusly {[^&]}) would be no problem.

                  On the real code against which I ran the RE it found all single &'s and
                  skipped all &&'s.

                  --
                  // Lee Silver
                  // Information Concepts Inc.

                  Dave Sexton wrote:
                  Hi Lee,
                  >
                  I'm suprised that works for you. I'm using VS 2005 as well and it doesn't
                  work for me. Actually, both of the examples that didn't work for me matched
                  absolutely nothing at all - not even a single "&".
                  >
                  I just tested it again. When I tested it the first time I just typed &'s
                  and &&'s (and some with trailing spaces) along the left margin of an empty
                  document, one per line. Apparently, [^&]&[^&] only works if there is some
                  combination of characters before the "&", even if it's whitespace, but it
                  doesn't just match "&" it makes the whitespace around it as well.
                  >
                  So, for instance, the resulting match would be " & ", not "&".
                  >
                  Also, it's kinda buggy. If I enter "&" along the left margin it doesn't
                  match. Then, if I insert whitespace before it, other than &'s, it still
                  doesn't match! I have to delete it and enter some strange combination of
                  tabs, spaces and characters before it first, then type &, and then it will
                  match. But even that doesn't work every time, although it seems to find " &
                  " in "if ((0 & 1) == 0)" with no problem :)
                  >
                  --
                  Dave Sexton
                  >
                  "Lee" <lsilver@inform ation-concepts.comwro te in message
                  news:1165085806 .761965.163910@ j72g2000cwa.goo glegroups.com.. .
                  Dave:
                  >
                  Yeah, on the syntax, ~ should have been ^ -- that's what I get for
                  posting un-tested code.
                  >
                  OTOH, I just tried [^&]&[^&] and it works as advertised -- it finds &'s
                  that are not also &&'s. This works in VS 2005; but I don't know about
                  VS2003.
                  >
                  Based on what the OP wanted, I would probably modify the RE to
                  [^&]&[^=&] in order to bypass the &= operator.
                  >
                  --
                  // Lee Silver
                  // Information Concepts Inc.
                  >
                  >
                  Dave Sexton wrote:
                  Hi Lee,

                  Good idea (incorrect syntax though). Based off that pattern I got thisto
                  work:

                  &~([&:b])

                  However, it will match the last "&" in "&&" when it's not immediately
                  followed by a space or tab. In other words, the pattern matches "&", and
                  the last "&" in "&&", but not, "&& ".

                  I thought it might be acceptable since it's common for && to be followed
                  by
                  at least one space in code. If you can't guarantee that, then the pattern
                  will not work for you.

                  Just FYI,

                  [^&]&[^&] and ~(&)&~(&)

                  didn't work for me, unfortunately.

                  HTH

                  --
                  Dave Sexton

                  "Lee" <lsilver@inform ation-concepts.comwro te in message
                  news:1165075827 .716564.276240@ 16g2000cwy.goog legroups.com...
                  The following untested RegExp might work:

                  [~&]&[~&]

                  It should find an & that is neither preceded nor followed by an &.

                  --
                  // Lee Silver
                  // Information Concepts Inc.

                  inpuarg wrote:
                  I want to find a & character using Regex. But not &&
                  How can i manage this in c# Quickfind window ?
                  --------------------------------------------------
                  ne kadar yaþarsan yaþa
                  sevdiðin kadardýr ömrün :(
                  --------------------------------------------------

                  Comment

                  • Dave Sexton

                    #10
                    Re: Find &amp; Replace Question

                    Hi Lee,
                    I haven't tried it, but I don't see why it wouldn't match the string " & "
                    Actually, I wrote that it was matching " & " - and that it was a problem.

                    But your addendum will probably work.

                    --
                    Dave Sexton

                    "Lee" <lsilver@inform ation-concepts.comwro te in message
                    news:1165092568 .735292.296650@ l12g2000cwl.goo glegroups.com.. .
                    Dave:

                    My RE will not find a single & that is in the left or right margin --
                    but in dealing with realistically entered code, the chances of one in
                    the left margin I think are nil; and as the right-most character only
                    marginally bigger.

                    I haven't tried it, but I don't see why it wouldn't match the string "
                    & " -- it should match any & preceded and followed by a non-&. OTOH, as
                    you say, the match will hi-light 3 characters because the RE matches 3
                    characters. For just doing a search, hi-lighting 3 characters should
                    not be a problem; and even if doing a Replace, specifying \1 and \2 in
                    the replacment string (and enclosing each [^&] in the RE in braces
                    thusly {[^&]}) would be no problem.

                    On the real code against which I ran the RE it found all single &'s and
                    skipped all &&'s.

                    --
                    // Lee Silver
                    // Information Concepts Inc.

                    Dave Sexton wrote:
                    Hi Lee,
                    >
                    I'm suprised that works for you. I'm using VS 2005 as well and it doesn't
                    work for me. Actually, both of the examples that didn't work for me
                    matched
                    absolutely nothing at all - not even a single "&".
                    >
                    I just tested it again. When I tested it the first time I just typed &'s
                    and &&'s (and some with trailing spaces) along the left margin of an empty
                    document, one per line. Apparently, [^&]&[^&] only works if there is some
                    combination of characters before the "&", even if it's whitespace, but it
                    doesn't just match "&" it makes the whitespace around it as well.
                    >
                    So, for instance, the resulting match would be " & ", not "&".
                    >
                    Also, it's kinda buggy. If I enter "&" along the left margin it doesn't
                    match. Then, if I insert whitespace before it, other than &'s, it still
                    doesn't match! I have to delete it and enter some strange combination of
                    tabs, spaces and characters before it first, then type &, and then it will
                    match. But even that doesn't work every time, although it seems to find "
                    &
                    " in "if ((0 & 1) == 0)" with no problem :)
                    >
                    --
                    Dave Sexton
                    >
                    "Lee" <lsilver@inform ation-concepts.comwro te in message
                    news:1165085806 .761965.163910@ j72g2000cwa.goo glegroups.com.. .
                    Dave:
                    >
                    Yeah, on the syntax, ~ should have been ^ -- that's what I get for
                    posting un-tested code.
                    >
                    OTOH, I just tried [^&]&[^&] and it works as advertised -- it finds &'s
                    that are not also &&'s. This works in VS 2005; but I don't know about
                    VS2003.
                    >
                    Based on what the OP wanted, I would probably modify the RE to
                    [^&]&[^=&] in order to bypass the &= operator.
                    >
                    --
                    // Lee Silver
                    // Information Concepts Inc.
                    >
                    >
                    Dave Sexton wrote:
                    Hi Lee,

                    Good idea (incorrect syntax though). Based off that pattern I got this
                    to
                    work:

                    &~([&:b])

                    However, it will match the last "&" in "&&" when it's not immediately
                    followed by a space or tab. In other words, the pattern matches "&",
                    and
                    the last "&" in "&&", but not, "&& ".

                    I thought it might be acceptable since it's common for && to be followed
                    by
                    at least one space in code. If you can't guarantee that, then the
                    pattern
                    will not work for you.

                    Just FYI,

                    [^&]&[^&] and ~(&)&~(&)

                    didn't work for me, unfortunately.

                    HTH

                    --
                    Dave Sexton

                    "Lee" <lsilver@inform ation-concepts.comwro te in message
                    news:1165075827 .716564.276240@ 16g2000cwy.goog legroups.com...
                    The following untested RegExp might work:

                    [~&]&[~&]

                    It should find an & that is neither preceded nor followed by an &.

                    --
                    // Lee Silver
                    // Information Concepts Inc.

                    inpuarg wrote:
                    I want to find a & character using Regex. But not &&
                    How can i manage this in c# Quickfind window ?
                    --------------------------------------------------
                    ne kadar yaþarsan yaþa
                    sevdiðin kadardýr ömrün :(
                    --------------------------------------------------

                    Comment

                    • inpuarg

                      #11
                      Re: Find &amp; Replace Question

                      Dear friends.
                      Thanks for insteresting and your helps. but noone seems working yet.
                      Strange. I thought this would be more easy :)

                      Let me change the question then :

                      I am exactly trying to find a single & character between " signs.

                      for instance : "asd & asasd" , "asd &" "asd& asasd" "asd&asasd"
                      But i don 't want to find && as logical And sign.

                      --------------------------------------------------
                      ne kadar yaþarsan yaþa
                      sevdiðin kadardýr ömrün :(
                      --------------------------------------------------

                      Comment

                      • inpuarg

                        #12
                        Re: Find &amp; Replace Question

                        I read the entire topic again and it seems like [^&]&[^&] is enough
                        for me. Thanks for your helps.



                        On Mon, 04 Dec 2006 11:53:23 +0200, inpuarg <inpuarg@wherel and.com>
                        wrote:
                        >Dear friends.
                        >Thanks for insteresting and your helps. but noone seems working yet.
                        >Strange. I thought this would be more easy :)
                        >
                        >Let me change the question then :
                        >
                        >I am exactly trying to find a single & character between " signs.
                        >
                        >for instance : "asd & asasd" , "asd &" "asd& asasd" "asd&asasd"
                        >But i don 't want to find && as logical And sign.
                        --------------------------------------------------
                        ne kadar yaþarsan yaþa
                        sevdiðin kadardýr ömrün :(
                        --------------------------------------------------

                        Comment

                        • Dave Sexton

                          #13
                          Re: Find &amp; Replace Question

                          Hi Lee,
                          My RE will not find a single & that is in the left or right margin --
                          but in dealing with realistically entered code, the chances of one in
                          the left margin I think are nil; and as the right-most character only
                          marginally bigger.
                          I just realized something, upon reading your comment again:

                          string value = @"
                          &
                          & &
                          & & & &";

                          The above is valid code that won't produce any matches. Given that the OP
                          is searching strings, it's possible, although unlikely that it will exist.

                          --
                          Dave Sexton

                          "Lee" <lsilver@inform ation-concepts.comwro te in message
                          news:1165092568 .735292.296650@ l12g2000cwl.goo glegroups.com.. .
                          Dave:



                          I haven't tried it, but I don't see why it wouldn't match the string "
                          & " -- it should match any & preceded and followed by a non-&. OTOH, as
                          you say, the match will hi-light 3 characters because the RE matches 3
                          characters. For just doing a search, hi-lighting 3 characters should
                          not be a problem; and even if doing a Replace, specifying \1 and \2 in
                          the replacment string (and enclosing each [^&] in the RE in braces
                          thusly {[^&]}) would be no problem.

                          On the real code against which I ran the RE it found all single &'s and
                          skipped all &&'s.

                          --
                          // Lee Silver
                          // Information Concepts Inc.

                          Dave Sexton wrote:
                          Hi Lee,
                          >
                          I'm suprised that works for you. I'm using VS 2005 as well and it doesn't
                          work for me. Actually, both of the examples that didn't work for me
                          matched
                          absolutely nothing at all - not even a single "&".
                          >
                          I just tested it again. When I tested it the first time I just typed &'s
                          and &&'s (and some with trailing spaces) along the left margin of an empty
                          document, one per line. Apparently, [^&]&[^&] only works if there is some
                          combination of characters before the "&", even if it's whitespace, but it
                          doesn't just match "&" it makes the whitespace around it as well.
                          >
                          So, for instance, the resulting match would be " & ", not "&".
                          >
                          Also, it's kinda buggy. If I enter "&" along the left margin it doesn't
                          match. Then, if I insert whitespace before it, other than &'s, it still
                          doesn't match! I have to delete it and enter some strange combination of
                          tabs, spaces and characters before it first, then type &, and then it will
                          match. But even that doesn't work every time, although it seems to find "
                          &
                          " in "if ((0 & 1) == 0)" with no problem :)
                          >
                          --
                          Dave Sexton
                          >
                          "Lee" <lsilver@inform ation-concepts.comwro te in message
                          news:1165085806 .761965.163910@ j72g2000cwa.goo glegroups.com.. .
                          Dave:
                          >
                          Yeah, on the syntax, ~ should have been ^ -- that's what I get for
                          posting un-tested code.
                          >
                          OTOH, I just tried [^&]&[^&] and it works as advertised -- it finds &'s
                          that are not also &&'s. This works in VS 2005; but I don't know about
                          VS2003.
                          >
                          Based on what the OP wanted, I would probably modify the RE to
                          [^&]&[^=&] in order to bypass the &= operator.
                          >
                          --
                          // Lee Silver
                          // Information Concepts Inc.
                          >
                          >
                          Dave Sexton wrote:
                          Hi Lee,

                          Good idea (incorrect syntax though). Based off that pattern I got this
                          to
                          work:

                          &~([&:b])

                          However, it will match the last "&" in "&&" when it's not immediately
                          followed by a space or tab. In other words, the pattern matches "&",
                          and
                          the last "&" in "&&", but not, "&& ".

                          I thought it might be acceptable since it's common for && to be followed
                          by
                          at least one space in code. If you can't guarantee that, then the
                          pattern
                          will not work for you.

                          Just FYI,

                          [^&]&[^&] and ~(&)&~(&)

                          didn't work for me, unfortunately.

                          HTH

                          --
                          Dave Sexton

                          "Lee" <lsilver@inform ation-concepts.comwro te in message
                          news:1165075827 .716564.276240@ 16g2000cwy.goog legroups.com...
                          The following untested RegExp might work:

                          [~&]&[~&]

                          It should find an & that is neither preceded nor followed by an &.

                          --
                          // Lee Silver
                          // Information Concepts Inc.

                          inpuarg wrote:
                          I want to find a & character using Regex. But not &&
                          How can i manage this in c# Quickfind window ?
                          --------------------------------------------------
                          ne kadar yaþarsan yaþa
                          sevdiðin kadardýr ömrün :(
                          --------------------------------------------------

                          Comment

                          • Lee

                            #14
                            Re: Find &amp; Replace Question

                            Dave:

                            Based on the OP's original message -- and his latest follow-up -- it
                            looks like he's looking for the bit-wise & operator without also
                            finding the logical && operator and not really searching strings. My RE
                            is based on that assumption.

                            As for your example, the RE should find no hits on the first 2 lines
                            (with &'s) and 4 hits on the last line (on my system it found the 4
                            hits).

                            --
                            // Lee Silver
                            // Information Concepts Inc.


                            Dave Sexton wrote:
                            Hi Lee,
                            >
                            My RE will not find a single & that is in the left or right margin --
                            but in dealing with realistically entered code, the chances of one in
                            the left margin I think are nil; and as the right-most character only
                            marginally bigger.
                            >
                            I just realized something, upon reading your comment again:
                            >
                            string value = @"
                            &
                            & &
                            & & & &";
                            >
                            The above is valid code that won't produce any matches. Given that the OP
                            is searching strings, it's possible, although unlikely that it will exist.
                            >
                            --
                            Dave Sexton
                            >
                            "Lee" <lsilver@inform ation-concepts.comwro te in message
                            news:1165092568 .735292.296650@ l12g2000cwl.goo glegroups.com.. .
                            Dave:
                            >
                            >
                            >
                            I haven't tried it, but I don't see why it wouldn't match the string "
                            & " -- it should match any & preceded and followed by a non-&. OTOH, as
                            you say, the match will hi-light 3 characters because the RE matches 3
                            characters. For just doing a search, hi-lighting 3 characters should
                            not be a problem; and even if doing a Replace, specifying \1 and \2 in
                            the replacment string (and enclosing each [^&] in the RE in braces
                            thusly {[^&]}) would be no problem.
                            >
                            On the real code against which I ran the RE it found all single &'s and
                            skipped all &&'s.
                            >
                            --
                            // Lee Silver
                            // Information Concepts Inc.
                            >
                            Dave Sexton wrote:
                            Hi Lee,

                            I'm suprised that works for you. I'm using VS 2005 as well and it doesn't
                            work for me. Actually, both of the examples that didn't work for me
                            matched
                            absolutely nothing at all - not even a single "&".

                            I just tested it again. When I tested it the first time I just typed &'s
                            and &&'s (and some with trailing spaces) along the left margin of an empty
                            document, one per line. Apparently, [^&]&[^&] only works if there is some
                            combination of characters before the "&", even if it's whitespace, but it
                            doesn't just match "&" it makes the whitespace around it as well.

                            So, for instance, the resulting match would be " & ", not "&".

                            Also, it's kinda buggy. If I enter "&" along the left margin it doesn't
                            match. Then, if I insert whitespace before it, other than &'s, it still
                            doesn't match! I have to delete it and enter some strange combination of
                            tabs, spaces and characters before it first, then type &, and then it will
                            match. But even that doesn't work every time, although it seems to find "
                            &
                            " in "if ((0 & 1) == 0)" with no problem :)

                            --
                            Dave Sexton

                            "Lee" <lsilver@inform ation-concepts.comwro te in message
                            news:1165085806 .761965.163910@ j72g2000cwa.goo glegroups.com.. .
                            Dave:

                            Yeah, on the syntax, ~ should have been ^ -- that's what I get for
                            posting un-tested code.

                            OTOH, I just tried [^&]&[^&] and it works as advertised -- it finds &'s
                            that are not also &&'s. This works in VS 2005; but I don't know about
                            VS2003.

                            Based on what the OP wanted, I would probably modify the RE to
                            [^&]&[^=&] in order to bypass the &= operator.

                            --
                            // Lee Silver
                            // Information Concepts Inc.


                            Dave Sexton wrote:
                            Hi Lee,
                            >
                            Good idea (incorrect syntax though). Based off that pattern I got this
                            to
                            work:
                            >
                            &~([&:b])
                            >
                            However, it will match the last "&" in "&&" when it's not immediately
                            followed by a space or tab. In other words, the pattern matches "&",
                            and
                            the last "&" in "&&", but not, "&& ".
                            >
                            I thought it might be acceptable since it's common for && to be followed
                            by
                            at least one space in code. If you can't guarantee that, then the
                            pattern
                            will not work for you.
                            >
                            Just FYI,
                            >
                            [^&]&[^&] and ~(&)&~(&)
                            >
                            didn't work for me, unfortunately.
                            >
                            HTH
                            >
                            --
                            Dave Sexton
                            >
                            "Lee" <lsilver@inform ation-concepts.comwro te in message
                            news:1165075827 .716564.276240@ 16g2000cwy.goog legroups.com...
                            The following untested RegExp might work:
                            >
                            [~&]&[~&]
                            >
                            It should find an & that is neither preceded nor followed by an &.
                            >
                            --
                            // Lee Silver
                            // Information Concepts Inc.
                            >
                            inpuarg wrote:
                            I want to find a & character using Regex. But not &&
                            How can i manage this in c# Quickfind window ?
                            --------------------------------------------------
                            ne kadar yaþarsan yaþa
                            sevdiðin kadardýr ömrün :(
                            --------------------------------------------------

                            Comment

                            • Dave Sexton

                              #15
                              Re: Find &amp; Replace Question

                              Hi Lee,
                              Based on the OP's original message -- and his latest follow-up -- it
                              looks like he's looking for the bit-wise & operator without also
                              finding the logical && operator and not really searching strings. My RE
                              is based on that assumption.
                              Not that it really matters at this point, but the OP clearly stated, "I am
                              exactly trying to find a single & character between " signs".
                              As for your example, the RE should find no hits on the first 2 lines
                              (with &'s) and 4 hits on the last line (on my system it found the 4
                              hits).
                              Yes, because my example certainly doesn't do what the OP wanted :)

                              Your example has always been closer, but not perfect. If I've implied that
                              I thought my example was better, that wasn't my intention here. My
                              intention was to get a working expression out of our conversation.
                              Regardless, it looks like that OP was satisfied with [^&]&[^&].


                              BTW, for some unknown reason my newsreader (OE) isn't prefixing your posts
                              with ">" automatically when I reply to them, which is very strange - I've
                              never seen that happen before. You might want to check out your settings to
                              see if it's something on your end of things. If you need to test something
                              out I'll be glad to help by responding to your posts here.

                              --
                              Dave Sexton


                              Comment

                              Working...