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

replacing a varying substring with itself plus

Hi,
I'd like to globally replace a substring specified by a regular
expression with itself along with some additional characters.
example:

var oldString = 'asdf BRACKETTHISasdfsdf sd asdBRACKETTHISasdf asd';

var newString =
oldString.replace(/\s\w*BRACKETTHIS\w*/g, '<' + ?some expression that
accesses current match? + '>' )

And newString winds up as:
'asdf <BRACKETTHISasdfsdf> sd <asdBRACKETTHISasdf>
asd'

Is there a way to do this, or do I have to use other methods?

Thanks for helps,
Kurt
Jul 23 '05 #1
1 1286
th*****************@yahoo.com (kurt) wrote:
Hi,
I'd like to globally replace a substring specified by a regular
expression with itself along with some additional characters.
example:

var oldString = 'asdf BRACKETTHISasdfsdf sd asdBRACKETTHISasdf asd';

var newString =
oldString.replace(/\s\w*BRACKETTHIS\w*/g, '<' + ?some expression that
accesses current match? + '>' )

And newString winds up as:
'asdf <BRACKETTHISasdfsdf> sd <asdBRACKETTHISasdf>
asd'

Is there a way to do this, or do I have to use other methods?

Thanks for helps,
Kurt


Add parentheses around the substring you care about and use $1 in the
replacement text.
.replace(/\s\w*(BRACKETTHIS)\w*/g, '<$1>' )

http://msdn.microsoft.com/library/en...mthreplace.asp

Regards,
Steve
Jul 23 '05 #2

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

Similar topics

13
by: yaipa | last post by:
What would be the common sense way of finding a binary pattern in a ..bin file, say some 200 bytes, and replacing it with an updated pattern of the same length at the same offset? Also, the...
0
by: Oliver Spiesshofer | last post by:
Hi, I would like to replace all strings in a table with regexp: the strings contain the substring "-na", and I would like to replace the whole table field with the original content but without...
3
by: Will McGugan | last post by:
Hi, Is there a simple way of replacing a large number of substrings in a string? I was hoping that str.replace could take a dictionary and use it to replace the occurrences of the keys with the...
5
by: Jim Lawton | last post by:
Hello group, I'm not very experienced in C#, but I can't find any example of this (common) programming problem. I have a string which contains a repeated substring - lets say it's like :- ...
7
by: VMI | last post by:
If I have the string "Héllo", how can I replace char (é) with an 'e'? I cannot use the String.Replace() fuction. It has to be by replacing one char with another. Thanks.
1
by: qwerty | last post by:
My end goal is to have a script that takes user input from one pageA, submits to pageB which then displays the parameter values entered on PageA. My problem is that the values are being displayed...
8
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post by:
I have a RichTextBox (rtfTerminal below) in which I would like to replace the last line with the last line minus its last character (i.e., do a backspace). I tried the following code, wherein I...
7
by: DarthBob88 | last post by:
I have to go through a file and replace any occurrences of a given string with the desired string, like replacing "bug" with "feature". This is made more complicated by the fact that I have to do...
4
by: sandvet03 | last post by:
I am trying to expand on a earlier program for counting subs and now i am trying to replace substrings within a given string. For example if the main string was "The cat in the hat" i am trying to...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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
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
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...

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.