Deja said:
I am new to regular expressions and I can't seem to figure out
following.
(1) Regular expression should find a match, if the given string
does NOT start with 90, 91, 31, or 32.
A pity about that "NOT". To find strings that match, you can just
do:
^((3[12])|(9[01])).*$
This is worth exploring if you're not too familiar with REs.
^((3[12])|(9[01])).*$ - the whole thing
^ - anchors RE to start of line
( ) - groups the two possible sub-patterns
( )|( ) - sub-pattern A *OR* sub-pattern B
3[12] - a "3" followed by a "1" or "2"
9[10] - a "9" followed by a "0" or "1"
.* - anything (i.e. rest of the line)
$ - anchors RE to end of line
NOTE: some systems require you to escape the grouping parentheses
and the "either/or" delimiter:
^\(\(3[12]\)\|\(9[01]\)\).*$
But the combination of the NOT and the double-digit prefixes makes
it a little harder. Something like this, perhaps:
^((9[^01])|(3[^12])|[^39]).*$
Broken out a bit:
^( (9[^01]) | (3[^12]) | [^39] ) .* $
This works by allowing lines that don't match.
^((9[^01])|(3[^12])|[^39]).*$ -
^( | | ).*$ - SOL, prefix, rest of line, EOL
(9[^01]) - "9" + NOT "0" or "1"
(3[^12]) - "3" + NOT "1" or "2"
[^39] - anything BUT NOT "3" or "9"
(2) Find a match, if the string contains DNI or 'DO NOT INSTALL'
anywhere in the string.
Easy:
(DNI)|(DO NOT INSTALL)