0

So I have a string of the English alphabet for example. But I don't know the alphabet very well but I do know that it starts with "abc" and that it ends in "xyz". I want to remove letters "b" to "x". I want to do something like str = str.replace("bc*x",""); or str = str.replace("bc"*"x",""); but I don't know how I can make it work or even if whether Asterisk will work like this in JavaScript.

how can I remove something like everything except for "efg" from "abcdefghijklm" without know what anything is except for "ef"?

Edited by nouth

4
Contributors
5
Replies
29
Views
4 Years
Discussion Span
Last Post by nouth
1

how can I remove something like everything except for "efg" from "abcdefghijklm" without know what anything is except for "ef"?

var alpha = 'abcdefghijklm';
var pattern = 'ef';
var re = new RegExp(pattern+".");
result = alpha.replace(re,"");
alert(result);
0

using for loop?

http://jsfiddle.net/cLLfq/

I don't understand this.

var alpha = 'abcdefghijklm';
var pattern = 'ef';
var re = new RegExp(pattern+".");
result = alpha.replace(re,"");
alert(result);

Is there a way to make result=efg? Or even just remove everything infront of efg.

Edited by nouth

1

Is there a way to make result=efg?

   var result  = alpha.match("efg");

Or even just remove everything infront of efg.

   var result = alpha.substring(alpha.match("efg").index);
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.