1

example1:

test "one" hi
this is test "two" check
I need to "three" this

example2:

test "one" hi
this is test "Two" check
I need to "three" this

Is it possible to check that text (some function) in quotes (one, two, three) are lowercase text ? In example1 this function return true , but in example2 this function return false;

a_subscriber
  • 4,062
  • 1
  • 18
  • 56

2 Answers2

3

If you use regular expressions as suggested by one of the other answers, you have to be careful to avoid checking text outside of quotes for uppercase letters. If you use just a single regular expression, you probably end up with the wrong result for

This is a "text" with some UPPERCASE letters outside the "quoted text"

You probably need to iterate through all the quoted text parts and check every one of them for an uppercase letter. For example:

(defun check-for-uppercase-in-quotes ()
 "Return t if quoted text containing uppercase letters is found"
  (save-excursion
    (goto-char (point-min))
    (let ((case-fold-search nil) (uppercasefound nil)) 
      (while (and (not uppercasefound) (re-search-forward "\"\\([\0-\377[:nonascii:]]*?\\)\"" nil t nil))
        (setq uppercasefound (string-match ".*[[:upper:]].*" (match-string 1))))
     uppercasefound)))

Edit: Modified the regular expression so that quoted text with multiple lines is correctly recognized.

StarBug
  • 479
  • 4
  • 10
2

For example, you can search upper-case letters in quotes.

(defun all-text-in-quotes-is-lowercase ()
  "Return t if text in quotes are lowercase text."
  (save-excursion
    (goto-char (point-min))
    (let ((case-fold-search nil))
      (not (search-forward-regexp "\".*[[:upper:]]+.*\"" nil t)))))
muffinmad
  • 2,300
  • 8
  • 11