Skip to content

Learn Python

  • Python
  • Cyber Security Basics
Learn Python
  • Python

    positive lookahead assertion

    Byadmin September 19, 2025September 19, 2025

    A positive lookahead assertion in Python’s re module is a zero-width assertion that checks if the pattern that follows it is present, without including that pattern in the overall match. It is written as (?=…). The key is that it’s a “lookahead”—the regex engine looks ahead in the string to see if the pattern inside…

    Read More positive lookahead assertionContinue

  • Python

    non-capturing group, Named Groups,groupdict()

    Byadmin September 19, 2025September 19, 2025

    To create a non-capturing group in Python’s re module, you use the syntax (?:…). This groups a part of a regular expression together without creating a backreference for that group. A capturing group (…) saves the matched text. You can then access this captured text using methods like group(1), group(2), etc. A non-capturing group (?:…)…

    Read More non-capturing group, Named Groups,groupdict()Continue

  • Python

    Special Sequences in Python Regex

    Byadmin September 17, 2025September 17, 2025

    1. \A and \Z – String Anchors \A – Matches ONLY at the beginning of the string \Z – Matches ONLY at the end of the string Example 1: \A – Start of string python import re text = “Hello World\nHello Python” pattern = r”\AHello” # Match “Hello” only at the VERY beginning matches =…

    Read More Special Sequences in Python RegexContinue

  • Python

    Curly Braces {} ,Pipe (|) Metacharacters

    Byadmin September 17, 2025September 17, 2025

    Curly Braces {} in Python Regex Curly braces {} are used to specify exact quantity of the preceding character or group. They define how many times something should appear. Basic Syntax: Example 1: Exact Number of Digits python import re text = “Zip codes: 12345, 9876, 123, 123456, 90210″ # Match exactly 5 digits pattern = r”\d{5}” # Exactly…

    Read More Curly Braces {} ,Pipe (|) MetacharactersContinue

  • Python

    (?),Greedy vs. Non-Greedy, Backslash () ,Square Brackets [] Metacharacters

    Byadmin September 16, 2025September 16, 2025

    The Question Mark (?) in Python Regex The question mark ? in Python’s regular expressions has two main uses: 1. Making a Character or Group Optional (0 or 1 occurrence) This is the most common use – it makes the preceding character or group optional. Examples: Example 1: Optional ‘s’ for plural words python import re pattern…

    Read More (?),Greedy vs. Non-Greedy, Backslash () ,Square Brackets [] MetacharactersContinue

  • Python

    Dot (.) ,Caret (^),Dollar Sign ($), Asterisk (*) ,Plus Sign (+) Metacharacters

    Byadmin September 16, 2025September 16, 2025

    The Dot (.) Metacharacter in Simple Terms Think of the dot . as a wildcard that can stand in for any single character. It’s like a placeholder that matches whatever character is in that position. What the Dot Does: Example 1: Finding Words with a Pattern python import re # Let’s find all 3-letter words that end with “at” text…

    Read More Dot (.) ,Caret (^),Dollar Sign ($), Asterisk (*) ,Plus Sign (+) MetacharactersContinue

  • Python

    AttributeError: ‘NoneType’ Error in Python re

    Byadmin September 16, 2025September 16, 2025

    AttributeError: ‘NoneType’ Error in Python re This error occurs when you try to call match object methods on None instead of an actual match object. It’s one of the most common errors when working with Python’s regex module. Why This Happens: The re.search(), re.match(), and re.fullmatch() functions return: When you try to call methods like .group(), .start(), or .span() on None, you get this error. Example That Causes…

    Read More AttributeError: ‘NoneType’ Error in Python reContinue

  • Python

    re.I, re.S, re.X

    Byadmin September 16, 2025September 16, 2025

    Python re Flags: re.I, re.S, re.X Explained Flags modify how regular expressions work. They’re used as optional parameters in re functions like re.search(), re.findall(), etc. 1. re.I or re.IGNORECASE Purpose: Makes the pattern matching case-insensitive Without re.I (Case-sensitive): python import re text = “Hello WORLD hello World” # Case-sensitive search matches = re.findall(r’hello’, text) print(“Case-sensitive:”, matches) # Output: [‘hello’] # Only finds lowercase…

    Read More re.I, re.S, re.XContinue

  • Python

    start(), end(), and span()

    Byadmin September 16, 2025September 16, 2025

    Python re start(), end(), and span() Methods Explained These methods are used with match objects to get the positional information of where a pattern was found in the original string. They work on the result of re.search(), re.match(), or re.finditer(). Methods Overview: Example 1: Basic Position Tracking python import re text = “The quick brown fox jumps over the lazy…

    Read More start(), end(), and span()Continue

  • Python

    group() and groups()

    Byadmin September 16, 2025September 16, 2025

    Python re group() and groups() Methods Explained The group() and groups() methods are used with match objects to extract captured groups from regex patterns. They work on the result of re.search(), re.match(), or re.finditer(). group() Method groups() Method Example 1: Basic Group Extraction python import retext = “John Doe, age 30, email: john.doe@email.com”# Pattern with multiple capture groupspattern = r'(\w+)\s+(\w+),\s+age\s+(\d+),\s+email:\s+([\w.]+@[\w.]+)’///The Pattern: r'(\w+)\s+(\w+),\s+age\s+(\d+),\s+email:\s+([\w.]+@[\w.]+)’Breakdown by Capture…

    Read More group() and groups()Continue

Page navigation

Previous PagePrevious 1 … 4 5 6 7 8 … 19 Next PageNext

© 2025 Learn Python - WordPress Theme by Kadence WP

Scroll to top
  • Python
  • Cyber Security Basics