Language: EN

cheatsheet-regex

Regular Expressions Cheatsheet

Regular expressions are text patterns used to search and manipulate strings of characters. They are widely used in programming for tasks such as searching, validation, and text substitution.

Examples in Different Languages

In these examples, the regular expression used is \broja\b, which searches for the word “roja” as a whole word. The examples search for this word in the text “La casa es roja y azul.” and display the matches found.

using System;
using System.Text.RegularExpressions;

class Program
{
    static void Main()
    {
        string text = "La casa es roja y azul.";

        // Pattern to search for the word "roja"
        string pattern = @"\broja\b";

        // Create the Regex object
        Regex regex = new Regex(pattern);

        // Find matches
        MatchCollection matches = regex.Matches(text);

        // Print the matches
        foreach (Match match in matches)
        {
            Console.WriteLine($"Found: {match.Value}");
        }
    }
}
let text = "La casa es roja y azul.";

// Pattern to search for the word "roja"
let pattern = /\broja\b/g;

// Find matches
let matches = text.match(pattern);

// Print the matches
matches.forEach(match => {
    console.log(`Found: ${match}`);
});
import re

text = "La casa es roja y azul."

# Pattern to search for the word "roja"
pattern = r'\broja\b'

# Find matches
matches = re.findall(pattern, text)

# Print the matches
for match in matches:
    print(f"Found: {match}")

Try it online

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
https://www.demo.com
email@domain.com
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum