String.prototype.TrimLeft = function (chars) { //debugger; var re = chars ? new RegExp("^[" + chars + "]+/", "g") : new RegExp(/^\s+/); return this.replace(re, ""); } String.prototype.TrimRight = function (chars) { var re = chars ? new RegExp("[" + chars + "]+$/", "g") : new RegExp(/\s+$/); return this.replace(re, ""); } String.prototype.Trim = function (chars) { return this.TrimLeft(chars).TrimRight(chars); }
var d = " ,asda,asdasd,asdasdads,asdasd, "; var ta = document.getElementById("txt"); var sonuc = d.Trim().Trim(','); ta.value = sonuc; </script> </body> </html>
var sOzellikler = ""; for (var ozellik in _enumPencereOzellikleri) { sOzellikler += ozellik + "=" + _enumPencereOzellikleri[ozellik]+","; }
// Pencere nesnesinde açılmış pencerenin adını ve referansını taşıyoruz. var Pencere = {}; Pencere.Adi = _sWindowName ? _sWindowName : 'pencere_' + Math.random(1000); Pencere.PencereOzellikleri = _enumPencereOzellikleri; Pencere.Window = window.open(_sUrl, Pencere.Adi, sOzellikler);
if (_enumEkranYeri) { f_PencereyiTasi(_enumEkranYeri, Pencere); } }
function f_PencereyiTasi(_enumEkranYeri, _pencere) { // Nokta ile pencerenin taşınacağı nihai nokta tutuluyor. var Nokta = { Top: 0, Left: 0 }; // Ekranın ve pencerenin width ve height bilgilerini hesaplamak için tutalım. var ekranW = screen.width; var ekranH = screen.height;
var pencereW = _pencere.PencereOzellikleri.width; var pencereH = _pencere.PencereOzellikleri.height;
var puan = (from p in DAO.context.TblOrtalamaPuanlar where p.M_RefTabloAdi.Equals("Videolar") && p.M_RefTabloPKId.Equals(this.M_VideoId) select p.M_Puan).Sum(p => (int?)p)
<script type="text/javascript"> var metin = "blah http://www.yahoo.com ile Yahoo adresine http://google.com ile Google a bağlanabilirsiniz."; var sonuc = metin.replace(/http:\/\/([a-z0-9.-]+)/g, '$1'); alert(sonuc); document.write(sonuc); </script>
This assumes that your anchors will always be in the form <a href="...">...</a> i.e. it won't work if there are any other attributes (for example, target). The regular expression can be improved to accommodate this.
To break down the regular expression:
/ -> start regular expression [^<]* -> skip all characters until the first <
( -> start capturing first token <a href=" -> capture first bit of anchor ( -> start capturing second token [^"]+ -> capture all characters until a " ) -> end capturing second token "> -> capture more of the anchor ( -> start capturing third token [^<]+ -> capture all characters until a <
) -> end capturing third token <\/a> -> capture last bit of anchor ) -> end capturing first token /g -> end regular expression, add global flag to match all anchors in string
Each call to our anonymous function will receive three tokens as the second, third and fourth arguments, namely arguments[1], arguments[2], arguments[3]:
arguments[1] is the entire anchor
arguments[2] is the href part
arguments[3] is the text inside
We'll use a hack to push these three arguments as a new array into our main matches array. The arguments built-in variable is not a true JavaScript Array, so we'll have to apply the split Array method on it to extract the items we want:
Array.prototype.slice.call(arguments, 1, 4)
This will extract items from arguments starting at index 1 and ending (not inclusive) at index 4.