Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 263
  • Last Modified:

Need regex to use in replace()

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
Eddie Shipman
Asked:
Eddie Shipman
  • 8
  • 6
1 Solution
 
leakim971PluritechnicianCommented:
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
 
Eddie ShipmanAll-around developerAuthor Commented:
It isn't working for me...
0
 
leakim971PluritechnicianCommented:
my test page ?
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
Eddie ShipmanAll-around developerAuthor Commented:
No, using your regex in my page located here:
http://www.partreports.com/treetest.php
0
 
leakim971PluritechnicianCommented:
What is your browser ?


Clipboard02.jpg
0
 
Eddie ShipmanAll-around developerAuthor Commented:
Firefox 3.6.10
0
 
Eddie ShipmanAll-around developerAuthor Commented:
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
 
leakim971PluritechnicianCommented:
seems it work :


Clipboard03.jpg
0
 
Eddie ShipmanAll-around developerAuthor Commented:
Not using IE7... Did you actually CLICK on the ... in the second dropdown?
Image1.png
0
 
Eddie ShipmanAll-around developerAuthor Commented:
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
 
Eddie ShipmanAll-around developerAuthor Commented:
Now, I don't even need the replace...
0
 
leakim971PluritechnicianCommented:
lol OK
0
 
Eddie ShipmanAll-around developerAuthor Commented:
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
 
leakim971PluritechnicianCommented:
Good to know! Thanks a lot for the points! Have fun!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 8
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now