Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6890167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:14:51+00:00 2026-05-27T06:14:51+00:00

Here is my text: TESTING TESTING test test test test test I want the

  • 0

Here is my text:

TESTING TESTING test test test test test

I want the regex to return true (or a match) if more than 50% of the sentence is in capitals.

In this case, it would return false because only 14 letters of 20 are capitals.

In applescript, I’d do:

set a to characters of "abcdefghijklmnopqrstuvwxyz"
    set ac to characters of "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    set this_message to characters of "TEST TEST TEST TEST test test test test test test"
    set x to 0 -- Counter
    set y to 1
    repeat with i from 1 to number of items in this_message
        set this_item to item i of this_message
        considering case
            if this_item is not " " then
                if this_item is in ac then
                    set x to x + 1
                end if
            end if
            if this_item is in {" ", ",", ".", "-"} then
                set y to y + 1
            end if
        end considering
    end repeat
    try
        if (round (x / ((count this_message) - y)) * 100) > 50 then
            return true
        else
            return false
        end if
    on error
        return false
    end try
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T06:14:52+00:00Added an answer on May 27, 2026 at 6:14 am

    Here is a PHP function that returns TRUE if a string contains more than half CAPs:

    // Test if more than half of string consists of CAPs.
    function isMostlyCaps($text) {
        $len = strlen($text);
        if ($len) {  // Check if string has zero length.
            $capscnt = preg_match_all('/[A-Z]/', $text, $matches);
            if ($capscnt/$len > 0.5) return TRUE;
        }
        return FALSE;
    }
    

    The above function compares the count of caps to the total length of the string (including whitespace and non-letters). If you want to compare to the number of non-whitespace chars, then the function is easily modified:

    // Test if more than half of non-whitespace chars in string are CAPs.
    function isMostlyCaps($text) {
        $len = preg_match_all('/\S/', $text, $matches);
        if ($len) {  // Check if string has zero length.
            $capscnt = preg_match_all('/[A-Z]/', $text, $matches);
            if ($capscnt/$len > 0.5) return TRUE;
        }
        return FALSE;
    }
    

    Here is a version that considers counts of whole words:

    // Test if more than half of "words" in string are all CAPs.
    function isMostlyCapWords($text) {
        // For our purpose a "word" is a sequence of non-whitespace chars.
        $wordcnt = preg_match_all('/\S+/', $text, $matches);
        if ($wordcnt) {  // Check if string has no words.
            $capscnt = preg_match_all('/\b[A-Z]+\b/', $text, $matches);
            if ($capscnt/$wordcnt > 0.5) return TRUE;
        }
        return FALSE;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Content: 1. Text is here. 20. More text. Why does this Vim search and
Can check out here alt text http://51hired.com/static/problem.bmp
Please take a look here: alt text http://img16.imageshack.us/img16/2810/errrp.jpg Why i got that error when
text = urllib.urlopen('www.text.com').read() frase = re.search(your text here(.*), text).group() With these code, I get
Let's say I have some original text: here is some text that has a
How can i change a normal font to bold font, Here the text should
Is either: <a href=#><h1>text here</h1></a> or <h1><a href=#>text here</a></h1> correct. Is there any benefit
<td valign=center colspan=2> <a href= class=table_desc > <span class=desc_info_butt></span> </a> text here </td> .desc_info_butt{
a simple question here Is there a way to change the text click here
Here is my try: @header(Content-type: text/html; charset=utf-8); @header(Location:/index.php); @header(Cache-Control: no-cache, must-revalidate); // HTTP/1.1 @header(Expires:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.