---
title: "jQuery word counter - exclude string in brackets"  
description: "jQuery word counter - exclude string in brackets"  
author: "Anonymous User"  
published: 2013-05-11  
updated: 2013-05-11  
canonical: https://www.mindstick.com/forum/863/jquery-word-counter-exclude-string-in-brackets  
category: "jquery"  
tags: ["jquery"]  
reading_time: 1 minute  

---

# jQuery word counter - exclude string in brackets

Hi [Expert](https://www.mindstick.com/articles/13120/an-expert-financial-advice-will-improve-your-finances)!\
I have an jQuery [function](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) for word counting in [textarea](https://www.mindstick.com/forum/155821/how-we-will-generate-textarea-control-using-htmlhelper-in-razor-view) field. Everything [works fine](https://answers.mindstick.com/qa/115732/my-software-works-fine-on-windows-10-but-crashes-on-windows-11-why), but i need [exclude](https://www.mindstick.com/forum/1756/wpf-linq-a-collection-to-include-or-exclude-items) words enclosed in triple brackets - [[[for example this [string](https://www.mindstick.com/articles/1527/string-split-in-c-sharp)]]] from counter. How do I modify the [regular expression](https://www.mindstick.com/articles/11909/java-regex-or-regular-expression-in-java) to make it work?\
function word_count(field) { var number = 0; var matches = $(field).val().match(/\b/g);\
if (matches) { number = matches.length / 2; } wordCounts[field] = number; var wordCounter = 0; $.each(wordCounts, function(k, v) { wordCounter += v;\
}); return wordCounter; }\
Thanks in [advance](https://www.mindstick.com/blog/33258/jee-mains-and-jee-advance-exams)!

## Replies

### Reply by AVADHESH PATEL

Hi Ankita!\
You can exclude words in brackets by making as following\
var matches = $(field).val().replace(/\[\[\[.*\]\]\]/g, '').match(/\b/g);\
This way you'll remove any string in the brackets and count the other one.


---

Original Source: https://www.mindstick.com/forum/863/jquery-word-counter-exclude-string-in-brackets

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
