Richtextfield counts quotation marks

Hey,
I want to counter a richtextfield without the html tags.

The code already replaces all html tags, but no quotation marks (“”, ‘’).
For some reason this marks get counted as 6 characters.

Is there a misstake in my replace regex?

export function richTextShortDescription_keyPress() {

 setTimeout(() => {
 var nWords = RichBoxCount($w('#richTextShortDescription').value.replace(/(<([^>]+)>)/ig, ''));
 let TextCounterRich = $w('#CounterRichfield').text = `${nWords} / 2.500 characters used.`;

 $w("#CounterRichfield").html = "<p style='font-size: 18px; font-family: Raleway; font-style: normal; text-align: right; color: #17B2DC;'>" + TextCounterRich + "</p>";
 }, 50)
}

function RichBoxCount(str) {
 return str.split('').filter(function (n) { return n !== '' }).length;
}

You will find your answer in the pic below.
Looking onto the pic, you will understand, why it counts 6 for a single QUOTATIONMARK.

I have had the same trouble, when working with RegEx & HTML-editor.
More useful information you will find here…
https://www.wix.com/velo/forum/coding-with-velo/regex-my-love

Hey Nick, well, I’m lazy. Very lazy. Gotta leave time for beer drinking. So, I recommend using a hack.

Add a plain text field to your site:

Set it to hidden so it doesn’t interfere with your site appearance.

Now we’ll let the hidden text element do the work for us. Do the following:

setTimeout(() => {
   let richtxt = $w('#richTextBox1').value;
   console.log('richtxt', richtxt);

   $w('#text2').html = val; // set the hidden text field to the rich text
   let plaintxt = $w('#text2').text; // now get the plain text
   console.log('plaintxt', plaintxt);

   // here you can add your code to get the count   
}, 50)

What’s nice about this is that you get plain text, and there’s no need for regex or other manipulations which detracts from other more important things, such as the next beer.

@yisrael-wix

Could you also suggest a solution for my issue, which is very very similar to this one?

To be found here …in mostly last of my posted comments…

So i can also have my beer :beers::stuck_out_tongue_winking_eye:

Hey Yisrael,
thanks for your answer, this is soo smart :slight_smile: I already got headache while looking for regex, that work…

So if somebody wants to make a Counter, too: Here’s my code:

setTimeout(() => {
        let richtxt = $w('#richTextShortDescription').value;

        $w('#text2').html = richtxt;
        let plaintxtCount = $w('#text2').text.length;

        let TextCounterRich = $w('#CounterRichfield').text = `${plaintxtCount} / 1.500 characters used.`;

        $w("#CounterRichfield").html = "<p style='font-size: 18px; font-family: Raleway; font-style: normal; text-align: right;'>" + TextCounterRich + "</p>";
    }, 50);

New I have time for a beer, too :beers:
Cheers

Have you already found a regex? Seems like you still have some problems, but now I understand why " gets counted as 6 characters.

Yeah, still stuck with a regEx problem in my own project. You can take a look onto it if interessted, perhaps you have an idea. I am sure that i am not far away from solution.

Tell me what you have found, perhaps it can help me somehow, to understand my own issued situation.