Sem I (Prak Grund Infor) - N2 Flashcards
Write a regex that matches first to “wa” followed by 3 or 4 “z” followed by “up”. Use Bash.
[wa]z{3,4}up
Write a regex that matches first to “wa” followed by 0,1,2 or 3 “z” followed by “up”. Use Bash.
waz{0,3}up
Write a regex using Bash for:
1) first at least two “a” or more
2) then arbitrary many “b”s (also no “b”!)
3) at least a “c” or more
aa+b*c+
Write a Regex that matches to a number followed by “ file found?” or “files found?”. Use Bash.
[0-9] (file|files) (found)\?
Write a regex with “man” at the begin of a word using Bash.
^man
#!/bin/bas string="The manual is comprehensive, but the manager is absent." pattern="^man" if [[ $string =~ $pattern ]]; then echo "The string matches the pattern." else echo "The string does not match the pattern." fi
Write a regex with “man” at the end of a word using Bash.
man\b
#!/bin/bash string="The manager is absent, but he's a handyman." pattern="man\b" if [[ $string =~ $pattern ]]; then echo "The string matches the pattern." else echo "The string does not match the pattern." fi
Your solution should match all “pdf”-files (files with suffix “.pdf”) that begin with “file”. Extract the filename without the suffix .pdf inside the first group. Use Bash.
^file(.+?).pdf$
#!/bin/bash filename="file_example.pdf" pattern="^file(.+?)\.pdf$" if [[ $filename =~ $pattern ]]; then echo "Filename: ${BASH_REMATCH[1]}" else echo "No match found." fi
Write a regex with “man” at the end or start of a word using Bash.
man\b
#!/bin/bash string="The manager is absent, but he's a handyman." pattern="man\b" if [[ $string =~ $pattern ]]; then echo "The string matches the pattern." else echo "The string does not match the pattern." fi
Bash regex to check if something at the start of the string or at the end of the string.
\b
Write a regex with “man” at the end of a word using Bash.
man$
#!/bin/bash string="The manager is absent, but he's a handyman." pattern="man\b" if [[ $string =~ $pattern ]]; then echo "The string matches the pattern." else echo "The string does not match the pattern." fi
! BASH
Regular expression for a negative lookahead assertion. It asserts that a particular pattern does not match at a specific point in the string.
Explain what is the strictfp class?
Когда класс объявлен как strictfp, все его методы будут соответствовать строгим правилам точности чисел с плавающей запятой.
Write a regex where at least a number followed by a dot “.” and at least a space followed again by “xyz”. using Bash.
[0-9]. +xyz
Wreite a regex using Bash where whitespace in the middle of the string
[a-z] +[a-z]
Write a regex using Linux Bash where No whitespace in the middle of the string.
^[[ : space: ]]*[^[:space:]]+[[:space:]]*$
Write a regex with “man” at the begin of a word. Using Bash Linux.
\bman
Write a regex using Linux Bash for matching group with or condition.
(cats|dogs)
Write a regex using Linux Bash for matches both “color” and “colour”.
colou?r
Write a regex using Linux Bash for matches both “ac” and “abc”.
ab?c
Write a regex using Linux Bash for matches both “file” and “files”.
file?s