473,396 Members | 1,990 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.

RegExp Question

Premise: Inserting data into a database form a <textarea> and
displaying this data through an HTML page.

When inserting data into a database via a text area and then displaying
this data any carriage return that was entered into the database was
lost. I Created a function to replace a carriage return with a <BR>. I
call this function when I display this data.

If I enter text inside <> into a database and then display this data,
any text that was within the <> is lost because it is considered an
HTML tag. How can I search the string for the brackets and actually
diplay them? I do not want to use Server.HTMLEncode before I insert the
data into the database. This is because we often query the database
from outside a web browser.

Here is my function I have for the carriage return. I need to figure
out how to accomplish this for both < and >. I am sure this is simple
but I do not know what the .pattern should be (for a carriage return it
is "\r".

SET regQuote = New RegExp
regQuote.pattern = "\r"
regQuote.global = True
catchCR = regQuote.Replace(strText, "<br>")

Thanks in Advance. I will post this to an ASP and a VBScript Group.

Jan 27 '06 #1
6 2191
Matt wrote on 27 jan 2006 in microsoft.public.inetserver.asp.general:
I will post this to an ASP and a VBScript Group.


Do not multipost, better crosspost.

Aswering a question and later finding that the same Q was answered elswhere
does not encourage. Netquette rules have a reason.

Crossposting = specifying more than one NG,
so that the thread runs common to both NGs [or more].

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jan 27 '06 #2
Matt,

You should use Server.HTMLEncode when displaying the contents of the field.

Use that first then perform your replace function.

It's wierd that you call this a RegExp question.

It's wierder still that you used RegExp at all
Dim sField ' contains value retrieved from DB.

sField = Server.HTMLEncode(sField)
sField = Replace(Replace(sField, vbCR, ""), vbLF, "<br />")
Note I kill all CRs then replace LFs. Depending other technologies you may
be using (one of note is XML) CRs can go missing leaving just LFs. LFs are
always there. The above code robustly handles this situation if it arises.
Anthony.
Jan 27 '06 #3
Matt wrote:
Premise: Inserting data into a database form a <textarea> and
displaying this data through an HTML page.

When inserting data into a database via a text area and then
displaying this data any carriage return that was entered
into the database was lost...
The carriage return is not lost when you store it in the DB. You will still
see it in your HTML source when attempting to display it.
...How can I search the string for the brackets and actually
diplay them? I do not want to use Server.HTMLEncode before I
insert the data into the database...


The usual way of dealing with this is to use Server.HTMLEncode when
injecting into an HTML stream. You can follow this with your replace
function to achieve both goals:

JScript:
<div><%=Server.HTMLEncode(val).replace(/\r\n/g,"<br>")%></div>

vbscript:
<% Set rx = New RegExp : rx.Pattern = vbCrLf : rx.Global = True %>
<div><%=rx.Replace(Server.HTMLEncode(val),"<br>")% ></div>

Keep in mind that you do not need to replace your carriage returns when
injecting back into a textarea:

<textarea><%=Server.HTMLEncode(val)%></textarea>

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
Jan 27 '06 #4

"Matt" <ma***********@manning-napier.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Premise: Inserting data into a database form a <textarea> and
displaying this data through an HTML page.

When inserting data into a database via a text area and then displaying
this data any carriage return that was entered into the database was
lost. I Created a function to replace a carriage return with a <BR>. I
call this function when I display this data.

If I enter text inside <> into a database and then display this data,
any text that was within the <> is lost because it is considered an
HTML tag. How can I search the string for the brackets and actually
diplay them? I do not want to use Server.HTMLEncode before I insert the
data into the database. This is because we often query the database
from outside a web browser.

Here is my function I have for the carriage return. I need to figure
out how to accomplish this for both < and >. I am sure this is simple
but I do not know what the .pattern should be (for a carriage return it
is "\r".

SET regQuote = New RegExp
regQuote.pattern = "\r"
regQuote.global = True
catchCR = regQuote.Replace(strText, "<br>")

Thanks in Advance. I will post this to an ASP and a VBScript Group.


I think VB uses chr(11) and chr(13) rather than the escape sequences like /r
or /n.
So look for chr(11) and replace it with a break tag seems like the thing to
do.
Jan 28 '06 #5
Hal Rosser wrote on 28 jan 2006 in
microsoft.public.inetserver.asp.general:
I think VB uses chr(11) and chr(13) rather than the escape sequences
like /r or /n.
So look for chr(11) and replace it with a break tag seems like the
thing to do.


Not chr(11)

================

VbCr = chr(13) ' carriage return

VbLf = chr(10) ' line feed

VbCrLf = chr(13) & chr(10) ' both

=================

In the old teletype [called telex in Europe] days
the mechanical carriage return took so long,
that the extra time given by sending the line feed at 45.45 baud
was also important not to miss the next printable character.

That's why there is VbCrLf and not VbLfCr.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jan 29 '06 #6
> > I think VB uses chr(11) and chr(13) rather than the escape sequences
like /r or /n.
So look for chr(11) and replace it with a break tag seems like the
thing to do.


Not chr(11)

================

VbCr = chr(13) ' carriage return

VbLf = chr(10) ' line feed

VbCrLf = chr(13) & chr(10) ' both


You're right - I was going by memory and should have looked it up first.
My point is that '/r' may work for javascript, but not for VB, that chr(n)
may be the course to take, but as you point out, vbcrlf works as well.
Feb 1 '06 #7

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

Similar topics

1
by: python_charmer2000 | last post by:
I want to match several regexps against a large body of text. What I have so far is similar to this: re1 = <some regexp> re2 = <some regexp> re3 = <some regexp> big_re = re.compile(re1 +...
19
by: Magnus Lie Hetland | last post by:
I'm working on a project (Atox) where I need to match quite a few regular expressions (several hundred) in reasonably large text files. I've found that this can easily get rather slow. (There are...
5
by: Lukas Holcik | last post by:
Hi everyone! How can I simply search text for regexps (lets say <a href="(.*?)">(.*?)</a>) and save all URLs(1) and link contents(2) in a dictionary { name : URL}? In a single pass if it could....
4
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...
3
by: Sped Erstad | last post by:
There must be a simple regexp reason for this little question but it's driving me nuts. Below is a simple regexp to determine if a string contains only numbers. I'm running these two strings...
2
by: Bill McCormick | last post by:
Hello, I'm new to VB.NET but have used regexp in Perl and VI. I'd like to read a regular expression from a file and apply it to a string read from another file. The regexp is simple word...
26
by: Matt Kruse | last post by:
Are there any current browsers that have Javascript support, but not RegExp support? For example, cell phone browsers, blackberrys, or other "minimal" browsers? I know that someone using Netscape...
7
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...
11
by: HopfZ | last post by:
I coudn't understand some behavior of RegExp.test function. Example html code: ---------------- <html><head></head><body><script type="text/javascript"> var r = /^https?:\/\//g;...
8
by: Darryl Kerkeslager | last post by:
Currently I am using the RegExp object to parse a large dataset in an Access table - but this table was exported from SQL Server, and the very correct question was asked - why not just do it in SQL...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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
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...
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.