473,480 Members | 1,807 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

RegExp.Replace

I'm using RegExp.Replace(string, string, string) to remove some pieces
of large strings. But I seem to be having trouble getting it to match
"all characters up to and including xxxxx" (which I thought would be
".*xxxxx" but it's not working). I can get it to match more precise
segments no problem, but not "all characters up to and including xxxxx"
or "xxxxx and all characters after it." Any ideas?
Regards,
David P. Donahue
dd******@ccs.neu.edu
http://www.cyber0ne.com
Nov 17 '05 #1
9 2078
"David P. Donahue" wrote:

I'm using RegExp.Replace(string, string, string) to remove some pieces
of large strings. But I seem to be having trouble getting it to match
"all characters up to and including xxxxx" (which I thought would be
".*xxxxx" but it's not working). I can get it to match more precise
segments no problem, but not "all characters up to and including xxxxx"
or "xxxxx and all characters after it." Any ideas?


You probably need the Singleline option, to force . to match \n.

--

www.midnightbeach.com
Nov 17 '05 #2
It was worth a try, but whenever I specify Singleline mode in the
options ("Replace(string, string, string, options)") the thread always
times out. The web server just returns a "thread was being aborted"
error after a bit of time passes.

I figured maybe I can use String.Replace to strip out all the carriage
returns, since I don't care if the string loaded with HTML code is all
one line or not, but that doesn't seem to be working either. If I use
String.Replace(Char.ToString((Char)13), "") it doesn't replace, but it
does match because if I use a non-empty string it adds it at each
carriage return.

Any ideas?
Regards,
David P. Donahue
dd******@ccs.neu.edu
http://www.cyber0ne.com
Jon Shemitz wrote:
"David P. Donahue" wrote:
I'm using RegExp.Replace(string, string, string) to remove some pieces
of large strings. But I seem to be having trouble getting it to match
"all characters up to and including xxxxx" (which I thought would be
".*xxxxx" but it's not working). I can get it to match more precise
segments no problem, but not "all characters up to and including xxxxx"
or "xxxxx and all characters after it." Any ideas?

You probably need the Singleline option, to force . to match \n.

Nov 17 '05 #3
"David P. Donahue" wrote:
It was worth a try, but whenever I specify Singleline mode in the
options ("Replace(string, string, string, options)") the thread always
times out. The web server just returns a "thread was being aborted"
error after a bit of time passes.


What, exactly, are you using as a Regex pattern?
I'm using RegExp.Replace(string, string, string) to remove some pieces
of large strings. But I seem to be having trouble getting it to match
"all characters up to and including xxxxx" (which I thought would be
".*xxxxx" but it's not working). I can get it to match more precise
segments no problem, but not "all characters up to and including xxxxx"
or "xxxxx and all characters after it." Any ideas?

You probably need the Singleline option, to force . to match \n.


--

www.midnightbeach.com
Nov 17 '05 #4
> What, exactly, are you using as a Regex pattern?

".*<--------------------START HERE-------------------->"
Regards,
David P. Donahue
dd******@ccs.neu.edu
http://www.cyber0ne.com
Nov 17 '05 #5
You'll probably need to be more specific about the problem you are
having, the structure/size of the text you are trying to replace, and
what you are trying to accomplish. What trouble exactly are you having?
For instance, are you trying to replace multiple instances of this
pattern?

The pattern you supplied will work just fine to replace a single
instance (with the Singleline option).

Nov 17 '05 #6
Basically, I read in a multi-line HTML file into a string (using
StreamReader). Once I have that string, I want to eliminate a lot of
header and footer stuff. In the HTML file itself, I have comments to
mark where I want this to happen. So, basically, I need to remove all
text (characters, special characters, whitespace, newlines, etc.) up to
the first comment and after the last comment. The comments themselves
are unique, so the first one and last one can be easily identified and
occur only once in the string.
Regards,
David P. Donahue
dd******@ccs.neu.edu
http://www.cyber0ne.com

Paul Walls wrote:
You'll probably need to be more specific about the problem you are
having, the structure/size of the text you are trying to replace, and
what you are trying to accomplish. What trouble exactly are you having?
For instance, are you trying to replace multiple instances of this
pattern?

The pattern you supplied will work just fine to replace a single
instance (with the Singleline option).

Nov 17 '05 #7
"David P. Donahue" wrote:
What, exactly, are you using as a Regex pattern?
".*<--------------------START HERE-------------------->"


As per Paul Walls' msg, that does work just fine with the Singleline
option.

A couple of thoughts:

1) It does NOT work with the IgnorePatternWhitespace option (which my
Regex Explorer sets by default) because the pattern contains white
space.

2) Do your HTMl files actually contain the HTML 'comment'
"<--------------------START HERE-------------------->"? Because that's
not really a comment. More to the point, if they actually contain
spaces between the last - and the START, or an extra space between
START and HERE, or a space between HERE and the -, then your pattern
won't work.

Try

".* < -+ \s* START \s+ HERE -+ >" (or ".* < ! -+ \s* START \s+ HERE -+") with the Singleline and IgnorePatternWhitespace options.


--

www.midnightbeach.com
Nov 17 '05 #8
>>".*<--------------------START HERE-------------------->"

As per Paul Walls' msg, that does work just fine with the Singleline
option.
I can't imagine why it wouldn't, except that whenever I use the Singline
option it just hangs on that line of code until the web server times out.
1) It does NOT work with the IgnorePatternWhitespace option (which my
Regex Explorer sets by default) because the pattern contains white
space.
I'm not sure what a "Regex Explorer" is, but is this option always on by
default? If so, is there a way to turn it off when I specify options in
the function call?
2) Do your HTMl files actually contain the HTML 'comment'
"<--------------------START HERE-------------------->"? Because that's
not really a comment. More to the point, if they actually contain
spaces between the last - and the START, or an extra space between
START and HERE, or a space between HERE and the -, then your pattern
won't work.
Actually, I typed my reply a bit too fast that time, just to give an
idea of the pattern. It's actually:
"<!-- --------------- START HERE --------------- -->"
And that's copied and pasted directly from the HTML file into Visual
Studio, so it's exact.
Try

".* < -+ \s* START \s+ HERE -+ >" (or ".* < ! -+ \s* START \s+ HERE -+
") with the Singleline and IgnorePatternWhitespace options.


Visual Studio is returning the error "Unrecognized escape sequence" when
I try to compile with that pattern. I also tried just replacing the
white spaces in my pattern with \s* but it gives the same error.
Regards,
David P. Donahue
dd******@ccs.neu.edu
http://www.cyber0ne.com
Nov 17 '05 #9
> > 1) It does NOT work with the IgnorePatternWhitespace option (which my
Regex Explorer sets by default) because the pattern contains white
space.


I'm not sure what a "Regex Explorer" is, but is this option always on by
default? If so, is there a way to turn it off when I specify options in
the function call?


An app I wrote to exoeriment with regexes.
<http://www.midnightbeach.com/dotnet/regexExplorer.html>
".* < -+ \s* START \s+ HERE -+ >" (or ".* < ! -+ \s* START \s+ HERE -+
") with the Singleline and IgnorePatternWhitespace options.


Visual Studio is returning the error "Unrecognized escape sequence" when
I try to compile with that pattern. I also tried just replacing the
white spaces in my pattern with \s* but it gives the same error.


Well, duh. You're mixing English quoting with C# quoting. Use

@".* < ! -+ \s* START \s+ HERE -+ >"

--

www.midnightbeach.com
Nov 17 '05 #10

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

Similar topics

20
3505
by: RobG | last post by:
I'm messing with getPropertyValue (Mozilla et al) and currentStyle (IE) and have a general function (slightly modified from one originally posted by Steve van Dongen) for getting style properties:...
1
3091
by: eysteinbye | last post by:
I have a problem with my RegExp. I need to replace some URLs with other URLs. I am using a URL-rewrite filter). The problem is that when the RegExp match just parts of the string, it does a...
4
7445
by: Jon Maz | last post by:
Hi All, I want to strip the accents off characters in a string so that, for example, the (Spanish) word "práctico" comes out as "practico" - but ignoring case, so that "PRÁCTICO" comes out as...
13
1817
by: Phat G5 (G3) | last post by:
I am weak when it comes to regexp but hoped someone might know in this case. I am trying to take a url like this : something.lasso?blah=blah&blah2=blah2&sort=hello&blah3=blah3 And remove the...
6
4492
by: jiing24 | last post by:
I try to use regexp to replace some html tags in DOM, but the result seems some problems, ================================ <Script language="javascript" type="text/javascript"> var config =...
7
3420
by: Csaba Gabor | last post by:
I need to come up with a function function regExpPos (text, re, parenNum) { ... } that will return the position within text of RegExp.$parenNum if there is a match, and -1 otherwise. For...
8
3569
by: reflex | last post by:
Hi, i have script with pattern (href=?(.*)({1}+)?), where i match any occurence of url and replace hyperlink so i have only anchor in it. var regExp = /href=?(.*)({1}+)?/ig; var wholeContent...
3
1444
by: yoni | last post by:
Hi, I am trying to write a regexp to find all the code on the header of entities in SQL Server (views, SPs, etc...) I got something like this: (.|\n)*((create view)|(create proc)|(create...
2
11664
by: X l e c t r i c | last post by:
Here: http://bigbangfodder.fileave.com/res/sandr.html I'm trying to use string.replace() for a basic search and replace form using textarea values as the regexp and replacement values for...
0
6912
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
7052
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7092
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...
1
6744
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
5348
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4790
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...
0
3000
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...
0
2989
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
565
muto222
php
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.