Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

regex in bash

Status
Not open for further replies.

qjulian

Technical User
Apr 25, 2016
2
PL
hello,
I want to check in bash shell if a string on VAR does not begin with "-" and at the same time if the string is built of [-_a-zA-Z0-9] but not longer than specified on LEN variable

LEN=10
[[ $VAR =~ ^[_a-zA-Z0-9][-_a-zA-Z0-9]{1,${LEN}}$ ]]

how to test length of whole marked in red is not greater than $LEN?


 

this sounds good

^[[:alnum:]][-[:alnum:]]{0,$((LEN-1))}$
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top