How do you create a grep that matches a word that starts with any random character, followed by a lower case b, an upper case C or the numbers 1 through 3, then followed by anything that isn't the number 7 or the number 9, followed by any number of characters and ending with the letter j or any number. OR that matches at least one letter (capital or lower case) followed by exactly 17 numbers

Study for the OSCP Linux Exam. Use our flashcards and multiple-choice questions to test your skills. Each query comes with detailed hints and explanations to enhance your preparedness. Get ready to conquer the exam!

Multiple Choice

How do you create a grep that matches a word that starts with any random character, followed by a lower case b, an upper case C or the numbers 1 through 3, then followed by anything that isn't the number 7 or the number 9, followed by any number of characters and ending with the letter j or any number. OR that matches at least one letter (capital or lower case) followed by exactly 17 numbers

Explanation:
The pattern is testing how to express two different match forms in one grep by using alternation. In basic regex used by grep, the OR operator is written as \|, so you can combine two substantial subpatterns with an escaped pipe to mean “this or that.” The first subpattern describes a word that starts with any character, then a next character that is either a lowercase b, an uppercase C, or one of the digits 1–3; this is captured with a character class like [bC1-3]. After that comes a character not equal to 7 or 9 ([^79]), followed by any number of characters (.*), and the word ends with either the letter j or a digit (the end condition is reflected by the final character class [0-9] or j). Anchors at the start and end ensure this whole form is matched as a single pattern when that branch is chosen. The second subpattern handles the other requirement: at least one letter (upper or lower case) followed by exactly 17 digits, expressed as [a-zA-Z]+[0-9]{17}. Using an escaped pipe to join these two subpatterns lets grep match either form in one pass, which is why this option is considered correct. The other choices typically misplace the alternation, fail to escape it properly, or misplace anchors, causing the pattern to either not match the intended forms or to behave unexpectedly.

The pattern is testing how to express two different match forms in one grep by using alternation. In basic regex used by grep, the OR operator is written as |, so you can combine two substantial subpatterns with an escaped pipe to mean “this or that.”

The first subpattern describes a word that starts with any character, then a next character that is either a lowercase b, an uppercase C, or one of the digits 1–3; this is captured with a character class like [bC1-3]. After that comes a character not equal to 7 or 9 ([^79]), followed by any number of characters (.*), and the word ends with either the letter j or a digit (the end condition is reflected by the final character class [0-9] or j). Anchors at the start and end ensure this whole form is matched as a single pattern when that branch is chosen.

The second subpattern handles the other requirement: at least one letter (upper or lower case) followed by exactly 17 digits, expressed as [a-zA-Z]+[0-9]{17}.

Using an escaped pipe to join these two subpatterns lets grep match either form in one pass, which is why this option is considered correct. The other choices typically misplace the alternation, fail to escape it properly, or misplace anchors, causing the pattern to either not match the intended forms or to behave unexpectedly.

Subscribe

Get the latest from Passetra

You can unsubscribe at any time. Read our privacy policy