Forum Moderators: open
note that \W will not remove numerals or underscores.
If you want them removed and do not want more than one "+" between words or a "+" at the beginning or end of the string, then try it like this...
<script type="text/javascript">var strings=[
'[Sports & Fitness] > General',
'<Webmaster>World{Forums} Rock@~',
'*&^Bird087__987brain(0#@"'
];for(c=0;c<strings.length;c++) {
strings[c]=strings[c].replace(/\W[red]¦[/red]\d[red]¦[/red]\_/g,'+').replace(/\+{2,}/g,'+').replace(/^(\+)[red]¦[/red](\+)$/g,'');
alert(strings[c]);
}
</script>
Note:- The l symbol above the backward slash on the keyboard is changed to ¦ by Webmaster World Forums. :(
I do not know the reason for this idiosyncrasy. ;)
So make sure that the three used in the script-(highlighted in red)- are replaced with the correct symbol.
birdbrain
Note, this would work in Perl, I do use Regex in JS but some things are different, so please test this and let me know.
var str = "[Sports & Fitness] > General";
var newstr = str.replace( /[^a-zA-Z]/, " "); // Replace any non letters with a space
var newerstr = newstr.replace( /\s+/, "+"); // Replace one or more spaces, with just a +