473,396 Members | 1,775 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Regular Expressions: matching anything *but* a specificed string

Hi,

Can't figure out the following:

<concept>
I want to match a specified string followed by any string that is *not* a
different specified string.
</concept>

<specific example>
strA = "value=&quot;"
strB = (anything other than strC, i.e. anything that is not "&quot;")
strC = "&quot;"

Sample string: value=&quot;Some text & punc. here!&quot;
Desired replacement: value="Some text & punc. here!"

It's not sufficient to simply replace "&quot;" with "\"" since I don't want
to replace all instances of "&quot;" in a given file.
</specific example>

Thanks for any help.
Jay
Nov 16 '05 #1
5 1997
When you doing this, just remember, a 'match' is consecutive characters ...
dont fall into the trap of thinking you can 'exclude' a string... what your
actually doing is creating two matches.

Now, as far as your problem, probably something like this will work....
(tested it with expresso, singleline ignore case settings)

The match string is --> (?<pre>.*?)(&quot;)(?<inner>.*?)(&quot;)(?<post>)
the replacement string is --> ${pre}"${inner}"${post}

Pretty easy to modify to do whatever else you might want, I definitely
recommend downloading Expresso, its free and really helps with RegExs.
"Jay S" <ja*@eatspammersforlunch.com> wrote in message
news:um**************@TK2MSFTNGP15.phx.gbl...
Hi,

Can't figure out the following:

<concept>
I want to match a specified string followed by any string that is *not* a
different specified string.
</concept>

<specific example>
strA = "value=&quot;"
strB = (anything other than strC, i.e. anything that is not "&quot;")
strC = "&quot;"

Sample string: value=&quot;Some text & punc. here!&quot;
Desired replacement: value="Some text & punc. here!"

It's not sufficient to simply replace "&quot;" with "\"" since I don't
want
to replace all instances of "&quot;" in a given file.
</specific example>

Thanks for any help.
Jay

Nov 16 '05 #2
That's called "negative lookahead": 'abc(?!def)' will match 'abc' unless
it's followed by 'def'.

Niki

"Jay S" <ja*@eatspammersforlunch.com> wrote in
news:um**************@TK2MSFTNGP15.phx.gbl...
Hi,

Can't figure out the following:

<concept>
I want to match a specified string followed by any string that is *not* a
different specified string.
</concept>

<specific example>
strA = "value=&quot;"
strB = (anything other than strC, i.e. anything that is not "&quot;")
strC = "&quot;"

Sample string: value=&quot;Some text & punc. here!&quot;
Desired replacement: value="Some text & punc. here!"

It's not sufficient to simply replace "&quot;" with "\"" since I don't
want
to replace all instances of "&quot;" in a given file.
</specific example>

Thanks for any help.
Jay

Nov 16 '05 #3
"Niki Estner" <ni*********@cube.net> wrote in message
news:Oh**************@TK2MSFTNGP11.phx.gbl...
That's called "negative lookahead": 'abc(?!def)' will match 'abc' unless
it's followed by 'def'.


Niki, I tried negative lookahead before posting but couldn't get it to
handle the text after the parens. Thanks, though.

Jay
Nov 16 '05 #4
"Richard Brown" <no****@stopspamnow.org> wrote in message
news:et*************@TK2MSFTNGP12.phx.gbl...
When you doing this, just remember, a 'match' is consecutive characters .... dont fall into the trap of thinking you can 'exclude' a string... what your actually doing is creating two matches.

Now, as far as your problem, probably something like this will work....
(tested it with expresso, singleline ignore case settings)

The match string is --> (?<pre>.*?)(&quot;)(?<inner>.*?)(&quot;)(?<post>)
the replacement string is --> ${pre}"${inner}"${post}

Pretty easy to modify to do whatever else you might want, I definitely
recommend downloading Expresso, its free and really helps with RegExs.


Thanks, Richard, that works! What was confusing to me was that you can
exclude specific characters and you can do negative lookaheads, so I thought
you should be able to specify a string to exclude.

Thanks also for the Expresso recommendation; I just downloaded it.

Jay
Nov 16 '05 #5
Check out the Regulator [1] as some are claiming they have abandoned
the use of Expresso. You know developers are just not loyal. :-)

--
<%= Clinton Gallagher, "Twice the Results -- Half the Cost"
Architectural & e-Business Consulting -- Software Development
NET cs*********@REMOVETHISTEXTmetromilwaukee.com
URL http://www.metromilwaukee.com/clintongallagher/

[1] http://royo.is-a-geek.com/iserializable/regulator/
"Jay S" <ja*@eatspammersforlunch.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
"Richard Brown" <no****@stopspamnow.org> wrote in message
news:et*************@TK2MSFTNGP12.phx.gbl...
When you doing this, just remember, a 'match' is consecutive characters ...
dont fall into the trap of thinking you can 'exclude' a string... what

your
actually doing is creating two matches.

Now, as far as your problem, probably something like this will work....
(tested it with expresso, singleline ignore case settings)

The match string is --> (?<pre>.*?)(&quot;)(?<inner>.*?)(&quot;)(?<post>) the replacement string is --> ${pre}"${inner}"${post}

Pretty easy to modify to do whatever else you might want, I definitely
recommend downloading Expresso, its free and really helps with RegExs.


Thanks, Richard, that works! What was confusing to me was that you can
exclude specific characters and you can do negative lookaheads, so I

thought you should be able to specify a string to exclude.

Thanks also for the Expresso recommendation; I just downloaded it.

Jay

Nov 16 '05 #6

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

Similar topics

1
by: Steve Zatz | last post by:
Is '@' a special character in regular expressions? I am asking because I don't understand the following: >>> import re >>> s = ' @' >>> re.sub(r'\b@','*',s) ' @' >>> s = ' a' >>>...
1
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make...
3
by: Tom | last post by:
I have struggled with the issue of whether or not to use Regular Expressions for a long time now, and after implementing many text manipulating solutions both ways, I've found that writing...
11
by: Martin Robins | last post by:
I am trying to parse a string that is similar in form to an OLEDB connection string using regular expressions; in principle it is working, but certain character combinations in the string being...
7
by: Billa | last post by:
Hi, I am replaceing a big string using different regular expressions (see some example at the end of the message). The problem is whenever I apply a "replace" it makes a new copy of string and I...
15
by: Mark Rae | last post by:
Hi, I'm trying to construct a RegEx pattern which will validate a string so that it can contain: only the numerical characters from 0 to 9 i.e. no decimal points, negative signs, exponentials...
25
by: Mike | last post by:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in matches. I would like to get what the actual regular expression is. In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART...
3
by: Zeba | last post by:
Hi guys, I need some help regarding regular expressions. Consider the following statement : System.Text.RegularExpressions.Match match =...
1
by: Ben | last post by:
I apologize in advance for the newbie question. I'm trying to figure out a way to find all of the occurrences of a regular expression in a string including the overlapping ones. For example,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
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...

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.