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 June 3rd, 2008, 09:50 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 139
Thanks: 0
Thanked 0 Times in 0 Posts
Default Regular Expression - Exec

Say I have a string that has something like this...

var str = "...toggleAlt('tab','text')..."

Now I know that I should be able to use regular expressions to extract it... but having issues... currently using this...

var myRe = /'(.*)'/g;
var result = myRe.exect(str)

but I only want to get the value of 'tab'... but I'm getting the value of 'tab','text'...

Any suggestions?

 
Old June 3rd, 2008, 10:22 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

You basically need to make sure that you exclude ' from the search between the two quotes:
Code:
'([^']*)'
Then the first match will have two groups, 'tab' and tab. The second match will have 'text' and text.

--

Joe (Microsoft MVP - XML)
 
Old June 3rd, 2008, 10:35 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 139
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

I tried your code, but I never get the 2nd grouping at all, I just get 'tab' and tab...

 
Old June 3rd, 2008, 10:39 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Well as I mentioned before I'm not supposed to use my mind reading skills on this forum but if you show the relevant code then perhaps I can help. You need to look at the match collection, not just the first match.

--

Joe (Microsoft MVP - XML)
 
Old June 3rd, 2008, 11:47 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

Hi Darkhalf!!
It would be good if you tell the exact solution you are looking??
Here--> but I only want to get the value of 'tab'... but I'm getting the value of 'tab','text'...
Are you looking for the match for 'tab'....
As Joe said ,provide details if you can..


Cheers :)

vinod





Similar Threads
Thread Thread Starter Forum Replies Last Post
regular expression MunishBhatia ASP.NET 2.0 Professional 5 May 22nd, 2007 07:59 AM
regular expression if-then smay Javascript 4 July 5th, 2005 12:10 PM
regular expression vohra_vikas2004 ADO.NET 3 November 18th, 2004 09:59 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





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