In the following script, can someone explain where the extra ‘,,,,’ are comming from, and better yet, how to get rid of them.
For example: 123+456 gives an alert message of ,123,,,,+,,456,,
What I would like to see is: 123,+,456
[code=php]
<html>
<head>
<title>Parse</title>
<script type=”text/javascript”>
function strToTokens(str) {
str = str.replace(/(s+)/g,’ ‘);
var tokens = new Array();
var tokens_index = 0;
tokens = str.split(/(w+)|(W+)/i);
alert(‘StrToTokens:’+tokens);
}
</script>
</head>
<body>
Parse Test<br>
<input type=”text” id=”StrInfo” value=””>
<button onClick=”strToTokens(document.getElementById(‘StrInfo’).value)”>Action</button>
<input name=”tst” type=”radio” value=”123+456″ onClick=”document.getElementById(‘StrInfo’).value=this.value”>
<input name=”tst” type=”radio” value=”a=12+(-34)+56″ onClick=”document.getElementById(‘StrInfo’).value=this.value”>
<input name=”tst” type=”radio” value=”c2=a^2+b^2″ onClick=”document.getElementById(‘StrInfo’).value=this.value”>
</body>
</html>
The extra radiobuttons are just for testing setup purposes.
Ideally I would like to split a string into Numbers, Variables (letters & numbers) and other characters like *,/,!, etc. to use in an Infix to Postfix (RPN) conversion script.
Any help is appreciated.