1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>remplacer un nombre aléatoire de virgules dans un chaîne.</title>
<meta http-equiv="Content-type" content="text/html; charset=UTF-8" />
<style type="text/css">
* {margin:0;padding:0;}
body {margin:10px;background:#000;color:#ddd;font-size:1em;font-family:Helvetica, Arial, sans-serif;}
div {width:10em;height:3em;background:#333;}
</style>
</head>
<body>
<script type="text/javascript">
<!--
var s1 = ",,1,2,7,,8,12,9,,";
var re1 = /,{2,}/g;
var re2 = /^,/g;
var re3 = /,$/g;
var s2 = s1.replace(re1, ",");
s2 = s2.replace(re2, "");
s2 = s2.replace(re3, "");
alert(s2);
//-->
</script>
</body>
</html> |
Partager