Professional Documents
Culture Documents
Construction
• Grouping:
• Expression: "(apple|banana)"
• Matches: "apple" or "banana" in "I like apple and banana."
• Alternation:
• Expression: "cat|dog"
• Matches: "cat" or "dog" in "I have a cat and a dog."
• Escape Sequences:
• Expression: "\\."
• Matches: "." in "The price is $5.99."
Example
• The regular expression \d{3}-\d{2}-\d{4} matches a string in the format of "123-
45-6789," which is a common pattern for Social Security numbers.
• Regular expressions are an essential tool for tasks like data validation (e.g., email
or phone number validation), text parsing (e.g., extracting data from log files), and
text searching (e.g., finding specific words or patterns in a document). They are
supported in many programming languages, including Python, JavaScript, Java,
and Perl, among others.
Matching an Extracting
Validating Parsing CSV Matching
Email Phone
URLs: Data HTML Tags
Address Numbers
Matching an
Email Address
Expression:^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$
Matches: john.doe@example.com
Expression: (\d{3}-\d{3}-\d{4})|(\(\d{3}\)\s*\d{3}-\d{4})
Expression: ^(https?|ftp)://[^\s/$.?#].[^\s]*$
Matches: https://www.example.com/page
Expression: ("[^"]*"|[^,]+)(,|$)
Expression: <\s*([a-zA-Z0-9]+)\s*>.*<\/\s*\1\s*>
Matches: "<div>Content</div>“
• url = "https://www.example.com/page/123"
• pattern = r"/page/(\d+)"
• match = re.search(pattern, url)
• page_number = match.group(1) # Extracts "123"
Data Science and Analytics (Python code
using Pandas):
• import pandas as pd
• image = Image.open('sample.png')
• text = pytesseract.image_to_string(image)
Content Management Systems (CMS)
(WordPress URL rewriting):
• RewriteEngine On
• RewriteRule ^news/([0-9]+)/?$ index.php?news_id=$1 [L]
Search Engines (Python code for search query
parsing):
• import re
Intermediate code
generator
3 Address
Lexical code
Analyzer
Code Optimizer
Syntax
Analyzer
Target Code
generation
Error
Handling Symbol Table
HLL LLL
Parser
• A parser is a software component or tool that is used to analyze and
interpret the structure of a given input, typically in the form of text or
code, based on a specific grammar or syntax.
• The primary purpose of a parser is to break down the input into its
constituent elements and determine whether it conforms to the expected
structure defined by the grammar.
Parser
• Parsers can be classified into different types based on their parsing
techniques, including recursive descent parsers, LL parsers, LR parsers,
and more. The choice of parser and parsing technique depends on the
complexity of the language or grammar being parsed and the specific
requirements of the application.
Cont
• Parser is a compiler that is used to break the data
into smaller elements coming from lexical
analysis phase.