473,812 Members | 2,852 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 :(
--------------------------------------------------
Dec 2 '06
14 2051
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 :(
--------------------------------------------------
Dec 4 '06 #11
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 <in*****@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 :(
--------------------------------------------------
Dec 4 '06 #12
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" <ls*****@inform ation-concepts.comwro te in message
news:11******** **************@ 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" <ls*****@inform ation-concepts.comwro te in message
news:11******** **************@ 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" <ls*****@inform ation-concepts.comwro te in message
news:11******** **************@ 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 :(
--------------------------------------------------

Dec 4 '06 #13
Lee
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" <ls*****@inform ation-concepts.comwro te in message
news:11******** **************@ 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" <ls*****@inform ation-concepts.comwro te in message
news:11******** **************@ 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" <ls*****@inform ation-concepts.comwro te in message
news:11******** **************@ 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 :(
--------------------------------------------------
Dec 4 '06 #14
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
Dec 4 '06 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1994
by: C. Titus Brown | last post by:
Hi all, while playing with PBP/mechanize/ClientForm, I ran into a problem with the way htmllib.HTMLParser was handling encoded tag attributes. Specifically, the following HTML was not being handled correctly: <option value="Small (6&quot;)">Small (6)</option> The 'value' attr was being given the escaped value, not the
1
3732
by: Xah Lee | last post by:
suppose you want to do find & replace of string of all files in a directory. here's the code: ©# -*- coding: utf-8 -*- ©# Python © ©import os,sys © ©mydir= '/Users/t/web'
19
2940
by: rbt | last post by:
Here's the scenario: You have many hundred gigabytes of data... possible even a terabyte or two. Within this data, you have private, sensitive information (US social security numbers) about your company's clients. Your company has generated its own unique ID numbers to replace the social security numbers. Now, management would like the IT guys to go thru the old data and replace as many SSNs with the new ID numbers as possible. You...
1
1138
by: Daniel Miller | last post by:
Question 1: Is there a pre-made solution for implimenting Find & Replace for a textbox, or will I have to roll my own using String.IndexOf? Question 2: When I right-click on a file -> Open With -> Browse -> select my program, it does not have a name. I tried finding some information about this, and I found my way to AssemblyInfo.cs. However, changing did not appear to have an effect. Any tips on either of those questions?
0
1429
by: ApexData | last post by:
I Want Access FIND&REPLACE to stay in FIND mode. Can I place the (Access FIND&REPLACE Dialog) in a popup/modal dialog form? I need to control this process to prevent the user from pressing keys on the MainForm that will cause the Forms AllowEdit to become True, in-turn putting REPLACE back on! I DONOT want this to happen.
6
2252
by: cj | last post by:
I'm receiving an xml formatted string that I pull data from by reading it into an xml document like this: Dim doc As New Xml.XmlDocument doc.LoadXml(respstr) Dim co_name As Xml.XmlNodeList = doc.GetElementsByTagName("co_name") textbox1.text = co_name(0).innertext Now I'm getting company names that have ampersands in them. I was not aware that was not allowed in xml and had no method of dealing with it.
2
1578
by: john | last post by:
In a table I have text field A. I would like to replace all the null values in field A to a real value, let's say 'Test'. When I use Find & Replace and I search for 'is null' and I press replace or replace all, no null value is found, so I can't replace anything. However, when I press Find Next in that same dialog then the null values are found. Anyone and idea what is happening here? Thanks, john
7
4634
by: John Nagle | last post by:
I've been parsing existing HTML with BeautifulSoup, and occasionally hit content which has something like "Design & Advertising", that is, an "&" instead of an "&amp;". Is there some way I can get BeautifulSoup to clean those up? There are various parsing options related to "&" handling, but none of them seem to do quite the right thing. If I write the BeautifulSoup parse tree back out with "prettify", the loose "&" is still in there. So...
3
1726
by: Crash | last post by:
VS2005 In the find/replace dialog if I make a regex like this I can find all of the "New" statements that instantiate a class with "System" in the name: <New>.*<System> But how - in the VS find/replace dialog - can I negate the "System" portion of the search? How do I say: find all lines with "New" that
0
9734
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9607
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10404
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10139
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7677
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6897
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5704
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4357
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3881
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.