Question

In: Computer Science

For each of the following Perl regular expressions, give a complete and precise description of the...

For each of the following Perl regular expressions, give a complete and precise description of the function of the regular expression, plus a related example string:

(a) /"([^"]*)"/

(b) /[-+]?\d+(\.\d*)?F\b/

(c) /(\D{2,}).*\[\1\]/

(d) /((.*?)\d)\s\2/

(e) /^[0-9]+\/\d+([+\-*\/]\=|([+]{2}|[-]{2}));$/

Solutions

Expert Solution

Q1)         The regular expression /"([^"]*)"/

"([^"]*)"

" "           Any text within double inverted commas.

Lets evaluate inside the brackets ( )

^"                     Anything except " (double inverted comma)

*                      It is a quantifier. Repetition of the preceding value 0 or any number of times. ie Anything except " (double inverted comma)

Example :

"This is an example"

Q2)         The regular expression /[-+]?\d+(\.\d*)?F\b/

[-+]?\d+(\.\d*)?F\b

[-+]                  Either a minus or plus sign.

[-+]?                ? means matches between zero and one times. So there can be minus, plus or no sign.

\d                     matches a digit (equal to [0-9]).

\d+                   digit repeated 1 or unlimited times.

\.                      matches character . (dot)        

\d*                   digit repeated zero or many times.

(\.\d*)?             ? means a decimal value related 0 or 1 time.

F                      Character F literally   

\b                     Matches word boundary. it means it has to end with F

This expression represent a negative or positive Fahrenheit value

Example :

-3.54F or +25.66F

Q3)         The regular expression /(\D{2,}).*\[\1\]/

(\D{2,}).*\[\1\]

\D                    Anything but not digit 0-9.

\D{2,}             Anything but not digit 0-9 matching 2 or more times ie two or more anything but not digits. Can be 2 characters like KR

.*                     matches any character but not end of line \n ie it shouldn't stop with KR alone

\[ \]                  means square brackets [ ]

\1                     matches the same text as most recently matched by (\D{2,}) ie 1st two characters, in our example KR

Example :

GABV[GA]                           : True

GABV dd[GA]                      : True

GBV[GA]                               : False

Q4)         The regular expression /((.*?)\d)\s\2/

(.*?)\d)\s\2

(.*?)                 matches any character (except for line terminators) zero or unlimited times.

\d                     matches a digit (equal to [0-9]).

\s                      matches any whitespace character like a tab or enter.

\2                     ((.*?)\d) is call the 1st group. and (.*?) is the 2nd group. \2 means match the 2nd group (.*?) ie characters 0 or more times

Any thing text or no text followed by a digit then a white space followed by text or no text.

Example :

I am 6 years old


Related Solutions

. Give an example of a string represented by each of the following regular expressions •...
. Give an example of a string represented by each of the following regular expressions • 0+ 1+ (11)* 0? • [0-9]+ ( (E|e) (\+|\-)? [0-9]+ )? • ([a..z] ([a..z] | [0..9])*)
Give a high-level description of what regular expressions are, and how JavaScript uses them.
Give a high-level description of what regular expressions are, and how JavaScript uses them.
Regular => Context-Free Give a proof by induction on regular expressions that: For any language A,...
Regular => Context-Free Give a proof by induction on regular expressions that: For any language A, if A is regular, then A is also context-free. You may assume that the statements from the previous Closure under Context-Free Languages problem are proved. R is a regular expression if RR is: a for some a∈alphabet Σ, the empty string ε, the empty set ∅, R​1​​∪R​2​​, sometimes written R​1​​∣R​2​​, where R​1​​ and R​2​​ are regular expressions, R​1​​∘R​2​​, sometimes written R​1​​R​2​​, where R​1​​ and...
Regular Expressions Assignment Write a regular expression for each of the following. Can you show output...
Regular Expressions Assignment Write a regular expression for each of the following. Can you show output please. A blank line (may contain spaces) Postal abbreviation (2 letters) for State followed by a space and then the 5-digit zip code A KU student username (Ex. lpork247) A “valid” email address (also explain how you defined “valid”) A SSN pattern (ddd-dd-dddd)
5 Regular => Context-Free Give a proof by induction on regular expressions that: For any language...
5 Regular => Context-Free Give a proof by induction on regular expressions that: For any language A, if A is regular, then A is also context-free. You may assume that the statements from the previous Closure under Context-Free Languages problem are proved.
Linux regular expressions: file name: lab3test.txt Create regular expressions that meet the following criteria. You may...
Linux regular expressions: file name: lab3test.txt Create regular expressions that meet the following criteria. You may use grep or egrep to answer these questions. 1.Match any lines that contain a phone number with the format 222-222-2222.
linux Regular expressions file name: lab3test.txt Create regular expressions that meet the following criteria. You may...
linux Regular expressions file name: lab3test.txt Create regular expressions that meet the following criteria. You may use grep or egrep to answer these questions. 1.Display all lines where the employee’s age is greater than 40 years old. Again, don’t think of this as a number, think of it as a series of characters.
RegEx (Regular Expressions) Make 8 regular expressions to filter a specific data set in Java and...
RegEx (Regular Expressions) Make 8 regular expressions to filter a specific data set in Java and explain what they do.
Give a brief description for each of the following: a) Describe the structures of the pulmonary...
Give a brief description for each of the following: a) Describe the structures of the pulmonary system b)Describe the pressures in the alveoli and pleural sac, and the flow of air during all the stages of an inhalation and exhalation c)Describe the role of surfactants, and how they work. d) Describe how flow of blood to regions of the lungs changes to match the flow of air
Give regular expressions for (c) C indentifiers (d) Binary strings consisting of either an odd number...
Give regular expressions for (c) C indentifiers (d) Binary strings consisting of either an odd number of 1s or an odd number of 0s
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT