473,387 Members | 1,925 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,387 software developers and data experts.

RegExp / Replace Question

To replace characters, I currently run the following code:

oStr = oStr.replace(/\xFC/g,"\t"); // replace sub-value mark(s) with tab(s)

Ideally, I'd like to replace the hard coded string \xFC with a variable such
as delim.

I tried:

oStr = oStr.replace(/delim/g,"\t"); // replace sub-value mark(s) with tab(s)

but that does not appear to work.

Is this possible? If so, how would I go about coding?

Thanks and regards, Ian Renfrew
Jul 23 '05 #1
4 1667
Ian Renfrew wrote:
To replace characters, I currently run the following code:

oStr = oStr.replace(/\xFC/g,"\t"); // replace sub-value mark(s) with tab(s)
Ideally, I'd like to replace the hard coded string \xFC with a variable such as delim.

I tried:

oStr = oStr.replace(/delim/g,"\t"); // replace sub-value mark(s) with tab(s)
but that does not appear to work.

Is this possible? If so, how would I go about coding?

Thanks and regards, Ian Renfrew


Use the RegExp constructor to compile the regex at run-time:

var re = new RegExp(delim, 'g');
oStr = oStr.replace(re, '\t');

http://www.webreference.com/js/column5/define.html

Jul 23 '05 #2
You'll need to use the regular expression constructor not regular
expression literals in your str.replace() function. The RegExp
constructor is passed a string that represents the regular expression
pattern, so you can make that string by concatenating some variable.

Jul 23 '05 #3
"Ian Renfrew" <ia*********@sympatico.ca> wrote in
news:Fn*******************@news20.bellglobal.com:
To replace characters, I currently run the following code:

oStr = oStr.replace(/\xFC/g,"\t"); // replace sub-value mark(s) with
tab(s)

Ideally, I'd like to replace the hard coded string \xFC with a
variable such as delim.

I tried:

oStr = oStr.replace(/delim/g,"\t"); // replace sub-value mark(s) with
tab(s)

but that does not appear to work.

Is this possible? If so, how would I go about coding?

Thanks and regards, Ian Renfrew

either,

delim=new RegExp("\\xFC", "g");

or

delim = /\xFC/g

then

oStr=oStr.replace(delim, "\t");

Jul 23 '05 #4
Thats done the trick. Learn something new each day. Thanks Rob, Mark and
John for your assistance.

.... Ian

"Ian Renfrew" <ia*********@sympatico.ca> wrote in message
news:Fn*******************@news20.bellglobal.com.. .
To replace characters, I currently run the following code:

oStr = oStr.replace(/\xFC/g,"\t"); // replace sub-value mark(s) with
tab(s)

Ideally, I'd like to replace the hard coded string \xFC with a variable
such as delim.

I tried:

oStr = oStr.replace(/delim/g,"\t"); // replace sub-value mark(s) with
tab(s)

but that does not appear to work.

Is this possible? If so, how would I go about coding?

Thanks and regards, Ian Renfrew

Jul 23 '05 #5

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

Similar topics

4
by: McKirahan | last post by:
How would I use a regular expression to remove all trailing Carriage Returns and Line Feeds (%0D%0A) from a textarea's value? Thanks in advance. Also, are they any great references for learning...
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...
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...
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...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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?
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...

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.