Reputation: 393
I am matching words that begin with certain prefixes.
This regex is working well for me but I am having trouble applying multiple terms in one match.
/re\S+/g;
I thought it would work with
/(re|http)\S+/g;
However the latter only returns matches from the second term.
Here is the full code:
function replacePrefix(input){
var re = /(#)\S+/g;
var specials = [];
var match;
while(match = re.exec(input)){
$('#text').html(input.replace(specials[0], "<span class='special'>"+specials[0]+"</span>"));
}
}
Upvotes: 0
Views: 2897
Reputation: 6136
function replacePrefix(input){
var re = /\b(?:re|http)\S+/g;
var specials = [];
var match;
while(match = re.exec(input)){
console.log(match);
}
}
replacePrefix("This is a sentence with really great urls in it like http://coolurl.com";);
["really"]
["http://coolurl.com"]
Upvotes: 1