🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.javascript
Article #51301

Zliczanie znakow ale bez urli

#51301
From: Jan
Date: Sat, 08 Jun 2013 10:26
21 lines
1785 bytes
Witam,

Potrzebuje zliczać znaki wprowadzone przez usera w polu textarea, ale z wyłączeniem urli. 
Doszedłem do tego, co poniżej, ale taka funkcja nie zlicza mi tylko pierwszego urla, drugi już tak. 
Zapewne problem jest w wyrażeniu, ale niestety nie wiem jak to rozkminić. Może jakaś porada?

function CountTxt(StrTxt, txtCount, totaltxt, e)
{
var exp = /(\b(https?):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/i;
// usuwamy do liczenia wszystkie urle zaczynajace sie na http(s)
var StrTxt2 = document.getElementById("formularz").value.replace(exp, "");

// StrTxt2.length to ilosc znakow liczona bez URLi.... StrTxt.value.length to ilosc znakow wszystich...
// ilosc znakow na URLe uzyskamy odejmujac StrTxt.value.length - StrTxt2.length
var StrURLe = StrTxt.value.length - StrTxt2.length;

    if (StrTxt2.length > totaltxt) {
	StrTxt.value = StrTxt.value.substring(0, totaltxt+StrURLe);}
    else {
	txtCount.value ='Zostało: ' + (totaltxt - StrTxt2.length) + ' znaków.';}
}
Technical Details
Message-ID: <kov0ss$nf2$1@node2.news.atman.pl>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!agh.edu.pl!news.agh.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!.POSTED!not-for-mail

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!agh.edu.pl!news.agh.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!.POSTED!not-for-mail
From: Jan <example@example.com>
Newsgroups: pl.comp.lang.javascript
Subject: Zliczanie znakow ale bez urli
Date: Sat, 8 Jun 2013 10:26:36 +0000 (UTC)
Organization: ATMAN - ATM S.A.
Lines: 24
Message-ID: <kov0ss$nf2$1@node2.news.atman.pl>
NNTP-Posting-Host: 78.30.113.236
Mime-Version: 1.0
X-Trace: node2.news.atman.pl 1370687196 24034 78.30.113.236 (8 Jun 2013 10:26:36 GMT)
X-Complaints-To: usenet@atman.pl
NNTP-Posting-Date: Sat, 8 Jun 2013 10:26:36 +0000 (UTC)
User-Agent: Pan/0.136 (I'm far too busy being delicious; GIT 926a150 git://git.gnome.org/pan2)
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit