473,499 Members | 1,573 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

pretty simple regex replace help needed

I need to replace a number in a string

str = "http://www.example.com?test=1&cat=0&ref=123213123213";

I want to replace the 0 after the cat= part with a new number. 0 could
be any number though so i need to use a reg exp to replace it.

str = str.replace(??????,newnumber);

I need help with the ?????? part :>

Any help is greatly appreciated.

Thx!

Jul 23 '05 #1
2 2255
moi
function reDemo() {
var r = new RegExp(/=0/)
var lnk = "http://www.example.com?test=1&cat=0&ref=123213123213";
var newlnk = lnk.replace( r, "=123" );
alert( newlnk );
}

<tg****@gmail.com> schreef in bericht
news:11**********************@f14g2000cwb.googlegr oups.com...
I need to replace a number in a string

str = "http://www.example.com?test=1&cat=0&ref=123213123213";

I want to replace the 0 after the cat= part with a new number. 0 could
be any number though so i need to use a reg exp to replace it.

str = str.replace(??????,newnumber);

I need help with the ?????? part :>

Any help is greatly appreciated.

Thx!

Jul 23 '05 #2
Lee
tg****@gmail.com said:

I need to replace a number in a string

str = "http://www.example.com?test=1&cat=0&ref=123213123213";

I want to replace the 0 after the cat= part with a new number. 0 could
be any number though so i need to use a reg exp to replace it.

str = str.replace(??????,newnumber);

I need help with the ?????? part :>


str = str.replace(/cat=\d+/,"cat="+newnumber);

Jul 23 '05 #3

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

Similar topics

6
1761
by: tshad | last post by:
Is there a way to use Regex inside of a tag, such as asp:label? I tried something like this but can't make it work: <asp:label id="Phone" text=Regex.Replace('<%# Container.DataItem("Phone")...
4
3828
by: Cor | last post by:
Hi Newsgroup, I have given an answer in this newsgroup about a "Replace". There came an answer on that I did not understand, so I have done some tests. I got the idea that someone said,...
3
8230
by: Craig Buchanan | last post by:
Is there a way to combine these two Replace into a single line? Regex.Replace(Subject, "\&", "&amp;") Regex.Replace(Subject, "\'", "&apos;") Perhaps Regex.Replace(Subject, "{\&|\'}", "{&amp;|&apos;}")...
17
1631
by: steve | last post by:
here's the deal...cvs, tick encapsulted data. trying to use regex's to validate records. here's an example row: 'AD,'BF','132465','06/09/2004','','BNSF','A','TYPE','1278','','BR','2999',''...
13
2341
by: Chris Lieb | last post by:
I am trying to write a regex that will parse BBcode into HTML using JavaScript. Everything was going smoothly using the string class replace() operator with regex's until I got to the list tag....
4
1901
by: MooMaster | last post by:
I'm trying to develop a little script that does some string manipulation. I have some few hundred strings that currently look like this: cond(a,b,c) and I want them to look like this: ...
4
1252
by: =?Utf-8?B?bWFnZ2ll?= | last post by:
hi, I need some help with a reg. expression. I have a comma delimited file with quotes. Not every field has quotes, only some. This is a sample of my file:...
2
1619
by: Sin Jeong-hun | last post by:
I'm trying to replace \n with @(representing the actual new line character). Of course, \\n should not be replaced. What I'm trying to do is simply what the good-old printf does. For example, "\\n...
0
1722
by: Karch | last post by:
I have these two methods that are chewing up a ton of CPU time in my application. Does anyone have any suggestions on how to optimize them or rewrite them without Regex? The most time-consuming...
0
7007
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
7171
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
7220
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
6893
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
7386
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...
0
5468
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
4918
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
4599
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
295
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.