Solved

Need regex to use in replace()

Posted on 2010-09-23
14
253 Views
Last Modified: 2012-05-10
I've got some strings that look like this:
Baby & Toddler > Baby Safety > ...

Open in new window

I want to take off the trialing
 > ...

Open in new window


Result should be
Baby & Toddler > Baby Safety

Open in new window


Can't use this:
  str.replace(" > ...", "", str);

Open in new window

I get an error: "invalid regular expression flag A" (in Firebug)

0
Comment
Question by:EddieShipman
  • 8
  • 6
14 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 33748403
You may use : str.replace(/\s>\s\.{3}/, "")

\s for space
\. for the dot and you have three to remove

Test page :


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<script language="javascript">
	var s = "Baby & Toddler > Baby Safety > ...";
	alert( s.replace(/\s>\s\.{3}/, "") );
</script>
</body>
</html>

Open in new window

0
 
LVL 26

Author Comment

by:EddieShipman
ID: 33748516
It isn't working for me...
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33748532
my test page ?
0
 
LVL 26

Author Comment

by:EddieShipman
ID: 33748804
No, using your regex in my page located here:
http://www.partreports.com/treetest.php
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33748871
What is your browser ?


Clipboard02.jpg
0
 
LVL 26

Author Comment

by:EddieShipman
ID: 33750640
Firefox 3.6.10
0
 
LVL 26

Author Comment

by:EddieShipman
ID: 33750644
You forgot to click the '...' in the second dropdown that contains baby Monitors. Do that and see if it still works for you.
If you select anything but the '...' in the last one, it doesn't append the  ' > ...'

0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 82

Expert Comment

by:leakim971
ID: 33750651
seems it work :


Clipboard03.jpg
0
 
LVL 26

Author Comment

by:EddieShipman
ID: 33750671
Not using IE7... Did you actually CLICK on the ... in the second dropdown?
Image1.png
0
 
LVL 26

Author Comment

by:EddieShipman
ID: 33750688
Fixed it...

Modified the .each function to not add the item if it's text = '...' like this:


.each(function() { 

  if($(this).text() != '...') {

    labels.push($(this).text()); 

  }

}); // .each

Open in new window

0
 
LVL 26

Author Comment

by:EddieShipman
ID: 33750691
Now, I don't even need the replace...
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33750711
lol OK
0
 
LVL 26

Author Closing Comment

by:EddieShipman
ID: 33750729
I'm giving you the points anyway.
This taxonomy is for an e-comemrce package to handle exports of their products to import into GoogleBase.
GoogleBase is the "store" for Google Checkout. You can import your products directly into it and sell from their store.
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33750732
Good to know! Thanks a lot for the points! Have fun!
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now