Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

TCL regexp matches strings that are all lower case

I am using regexp to ensure the string is all lower case,but it seems not useful.

Here’s my code

set name aAaaaA
if { [regexp {/^[a-z]$g} $name] } {
   puts "continue"
} else {
   puts "String is not lowercase. Please enter again"
}

I need to ensure the input is all lowercase ,and without any uppercase,symbol

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

And I’ve found [regexp (?=.*[\L]) $name] can express characters other than lowercase letters,but it’s not useful,too.

Can anyone help for this? Thanks!

>Solution :

You can use

set name aAaaaA
if { [regexp {^[[:lower:]]+$} $name] } {
   puts "continue"
} else {
   puts "String is not lowercase. Please enter again"
}

See the Tcl demo.

If an empty string is valid, replace + with *.

More details:

  • ^ – start of string
  • [[:lower:]]+ – one or more lowercase letters
  • $ – end of string.
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading