473,800 Members | 2,499 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 #1
14 2048
Hi,

Then just use a single "&".

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

--
Dave Sexton

"inpuarg" <in*****@wherel and.comwrote in message
news:6r******** *************** *********@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 :(
--------------------------------------------------

Dec 2 '06 #2
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 :(
--------------------------------------------------
Dec 2 '06 #3
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)"
http://msdn2.microsoft.com/en-us/lib...cs(VS.80).aspx

--
Dave Sexton

"inpuarg" <in*****@wherel and.comwrote in message
news:iu******** *************** *********@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 :(
--------------------------------------------------

Dec 2 '06 #4
Lee
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 2 '06 #5
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 2 '06 #6
Lee
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 2 '06 #7
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 2 '06 #8
Lee
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" <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 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" <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 2 '06 #9
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" <ls*****@inform ation-concepts.comwro te in message
news:11******** **************@ 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" <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 2 '06 #10

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
3730
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
2938
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
1428
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
2250
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
1577
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
4631
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
9690
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
9550
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
10273
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...
1
10250
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6811
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
5469
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5603
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4149
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
3764
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.