1

(I have posted this on Stack Exchange as well)

I have a Drupal 7 page on which I need to remove text bracketed by "Keywords:" and "Description:", there are a number of text blocks all with the class .feedDesc

Page is here: http://www.cafe.gen.nz/node/236/feed-items

I have this working on a plain html page with this Jquery below but can not for the life of me make it work in the Drupal setup:

  $('p.feedDesc').html( function (index,text) {
    var regex = /Keywords(.*)Description/;
    return text.replace(regex,"");
  });

On the site the below does work indicating the whole stack is good.

  $('p.feedDesc').html( function (index,text) {
    return text.replace("Keywords","Foobar");
  });

Help !

Any ideas?

Update:

This works to do the find/replace:

    $('p.feedDesc').html( function (index,text) {
      text = text.replace(/Keywords:([^"]*)Description:/gi,"");        
      return text;
    });

However I also need to trim whitespace and $.trim does not work:

    $('p.feedDesc').html( function (index,text) {
      text = text.replace(/Keywords:([^"]*)Description:/gi,"");
      text = $.trim(text);        
      return text;
    });

1 Answer 1

-1

If that's the exact code, then

var regex = /Keywords(.*)Description/;

should be

var regex = '/Keywords(.*)Description/';
1
  • Regexs in javascript don't need quotes around them
    – Clive
    Commented Oct 18, 2012 at 11:44

Not the answer you're looking for? Browse other questions tagged or ask your own question.