Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 3rd, 2008, 09:50 AM
Friend of Wrox
 
Join Date: Mar 2004
Location: Ottawa, , Canada.
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?

Reply With Quote
  #2 (permalink)  
Old June 3rd, 2008, 10:22 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
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)
Reply With Quote
  #3 (permalink)  
Old June 3rd, 2008, 10:35 AM
Friend of Wrox
 
Join Date: Mar 2004
Location: Ottawa, , Canada.
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...

Reply With Quote
  #4 (permalink)  
Old June 3rd, 2008, 10:39 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
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)
Reply With Quote
  #5 (permalink)  
Old June 3rd, 2008, 11:47 AM
Friend of Wrox
 
Join Date: Oct 2004
Location: delhi, delhi, India.
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 11:25 PM.


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