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;

  • 3
    What have you tried? – phils May 19 at 14:13
  • @phils function that return true if all text in quotes print in lowercase. Else return false. Smt like this. – a_subscriber May 19 at 15:04
  • 1
    Check where? Check how (interactively, by program)? What action do you mean by "check" (return a Boolean? do something else?) The question is unclear. – Drew May 19 at 15:10
  • @Drew I updated my post – a_subscriber May 20 at 7:05
  • 1
    What have you tried so far to answer your own question? What’s not working yet? – Dan May 20 at 18:00
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.

  • 1
    Great! The one thing left to do is include \n to regexp to handle multiline quoted texts ;) – muffinmad May 22 at 9:31
  • @muffinmad: Well spotted:) Fixed it now. – StarBug May 22 at 10:37
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)))))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.