Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 8th, 2006, 05:51 PM
Registered User
 
Join Date: Jan 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default trouble with js regular expression

hi,
i'm checking for a regular expression in a parameter passed into a function and i just cannot seem to get what i want to do done right..

code:

var searchString = /Form1.\g/;
var p_item_fixed = arguments[0].toString();

if (p_item_fixed.search(searchString)) {
   p_item_fixed.replace(searchString, "");
}

alert(p_item_fixed);

for some reason it finds the regular expression: "Form1." but it never does the replace. I'm sure it's something mundane I'm missing, but I'm pulling my hair out about this and I need to figure this out.

Any help would be sincerely appreciated.

Thanks,
Ian K. Dayton, OH
 
Old March 9th, 2006, 06:09 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

Hii kapstan!!
Two lines you need to change
1>var searchString = /Form1.\g/;
  to var searchString = /Form1\./g;
2> p_item_fixed.replace(searchString, "");
to p_item_fixed=p_item_fixed.replace(searchString, "");

so your code will be
var searchString = /Form1\./g;
var p_item_fixed = arguments[0].toString();
if (p_item_fixed.search(searchString)) {
   p_item_fixed=p_item_fixed.replace(searchString, "");
}

alert(p_item_fixed);

Hope this will help you.


Cheers :)

vinod
 
Old March 9th, 2006, 06:54 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

Hii Hii kapstan!!

One thing i noticed that!!
we can do the same thing with test() method of Regular expression.
Now I think test() is faster than search(),Please anyone have idea about it ??then let me know.

   [search method first call -->test method]
or [test method first--->call search() method ??? ,Still in not sure]



var searchString = /Form1\./g;
var p_item_fixed = arguments[0].toString();

if (searchString.test(p_item_fixed)) {
  p_item_fixed=p_item_fixed.replace(searchString, "");
}
alert(p_item_fixed);


plz visit for more info
http://www.siteexperts.com/tips/func...ts23/page2.asp


Cheers :)

vinod
 
Old March 9th, 2006, 06:00 PM
Registered User
 
Join Date: Jan 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks for the tip. I ended up completely redoing how I am approaching this problem and returning the parameter passed in to another function and doing the string manipulation there.

Thanks!







Similar Threads
Thread Thread Starter Forum Replies Last Post
Regular Expression balajinrs Visual Studio 2005 0 July 24th, 2008 02:11 AM
Regular Expression NewToXSL ASP.NET 1.0 and 1.1 Basics 1 June 13th, 2006 02:52 PM
Regular Expression Help Greg Griffiths Javascript How-To 4 November 12th, 2004 05:33 AM
Regular Expression DARSIN General .NET 2 November 9th, 2004 08:30 AM
Regular expression help!!! alex_read Javascript 4 August 18th, 2004 03:44 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.