Good day stack overflow.

I'm a noob in using regex and here is my problem - I need to check a password if it contains 4 consecutive characters. so far what I have just covered is regarding the digits. Here is my regex:

ascending digits - ^.?(?:0123|1234|2345|3456|4567|5678|6789).$

descending digits - ^.?(?:9876|8765|7654|6543|5432|4321|3210).$

This works only for the digits. I know this is already an overkill in regex so I dont want to do it with the letters. It will be waaay too overkill if I do that.

abcdblah //true because of abcd

helobcde //true because of bcde

dcbablah //true beacause of dcba

heloedcb //true because of edcb

Any help would be highly appreciated. Thanks stackoverflow.


Question: How to verify the line starts with a number while reading variable line by line in shell
Answer: If I understand you correctly then you want something like this (note that I presume you are using bash for some things below, if this is not the case it would have to be modified somewhat).

First, get the bulleted number plus the string on the next line. A little sed will do it.

sed -n -e '/^[0-9]/{s/\([0-9]*\).*/\1/;h;n;s/^ *//;H;x;s/\n/ /p;d;}' &lt;&lt;&lt;"$line"


Next we just need to read the lines, count the lines and store them in variables.

operations=0
while read -r n str ; do
    let operations+=1
    printf '%d, %d, %s\n' "$operations" "$n" "$str"
done &lt; &lt;(sed -n -e '/^[0-9]/{s/\([0-9]*\).*/\1/;h;n;s/^ *//;H;x;s/\n/ /;p;d;}' &lt;&lt;&lt;"$line")

printf 'Opertions = %d\n' "$operations"


During each loop n is the number from the bullet and str is the string from the following line.