{"id":973,"date":"2021-11-11T08:37:30","date_gmt":"2021-11-11T08:37:30","guid":{"rendered":"https:\/\/ethosspace.com\/programmers\/?p=973"},"modified":"2023-05-23T08:32:52","modified_gmt":"2023-05-23T08:32:52","slug":"how-to-count-occurrences-of-words-characters-sentences-using-regular-expression","status":"publish","type":"post","link":"https:\/\/ethosspace.com\/programmers\/how-to-count-occurrences-of-words-characters-sentences-using-regular-expression\/","title":{"rendered":"How to count occurrences of words, characters, sentences using Regular Expression"},"content":{"rendered":"\n<p>Here is a Regular Expression regex to count words, to count blank spaces, to count sentences, to count paragraphs in Java script.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Regular Expression to count words in Text.<\/h2>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code>text.match(\/(\\w+)\/g).length;<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Regular Expression to count paragraphs in text.<\/h2>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code>text.replace(\/\\n$\/gm, &#39;&#39;).split(\/\\n\/).length;<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Regular Expression to count Sentences in Text.<\/h2>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code>text.split(\/[\\.!\\?]+\\s\/g).filter(Boolean).length;<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Regular Expression to count spaces in Text.<\/h2>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code>text.split(&quot; &quot;).length - 1;<\/code><\/pre><\/div>\n\n\n\n<p>Use this <a href=\"https:\/\/ethosspace.com\/programmers\/character-word-counter-online\/\" title=\"Simple Character Word Counter Online Free Tool\">Word Character Counter Online Tool.<\/a> Another Tool is used to <a href=\"https:\/\/ethosspace.com\/programmers\/capitalize-every-first-character-of-word\/\" title=\"Free Tool to Capitalize First Character of Every Word\">capitalize the first character of every word.<\/a><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here is a Regular Expression regex to count words, to count blank spaces, to count sentences, to count paragraphs in Java script. Regular Expression to count words in Text. Regular Expression to count paragraphs in text. Regular Expression to count Sentences in Text. Regular Expression to count spaces in Text. Use this Word Character Counter [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","footnotes":""},"categories":[19],"tags":[],"class_list":["post-973","post","type-post","status-publish","format-standard","hentry","category-java-script"],"aioseo_notices":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"sparkling-featured":false,"sparkling-featured-fullwidth":false,"tab-small":false},"uagb_author_info":{"display_name":"program45_-rt8nb","author_link":"https:\/\/ethosspace.com\/programmers\/author\/program45_-rt8nb\/"},"uagb_comment_info":1,"uagb_excerpt":"Here is a Regular Expression regex to count words, to count blank spaces, to count sentences, to count paragraphs in Java script. Regular Expression to count words in Text. Regular Expression to count paragraphs in text. Regular Expression to count Sentences in Text. Regular Expression to count spaces in Text. Use this Word Character Counter&hellip;","_links":{"self":[{"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/posts\/973","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/comments?post=973"}],"version-history":[{"count":3,"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/posts\/973\/revisions"}],"predecessor-version":[{"id":1402,"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/posts\/973\/revisions\/1402"}],"wp:attachment":[{"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/media?parent=973"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/categories?post=973"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/tags?post=973"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}