Search for/in text using regular expressions (Regex)?
Regular expressions (also called regex) are powerful tools to search for, extract or manipulate text patterns in strings. Here's an overview of how you can use regular expressions to search for text in different scenarios.
This will find every occurrence of the word "desktop".
2.) Search for a word regardless of case
Example: Search for "desktop" or "Desktop" or "DESKTOP"
(?i)desktop
The (?i) at the beginning makes the search case-insensitive.
3.) Search for a pattern with wildcards
Example: Search for "color" followed by any word
color\s\w+
This is:
- \s for a space
- \w+ for one or more alphanumeric characters.
4.) Search for a number
Example: Search for a number (e.g. a time)
\d+
The \d+ searches for one or more digits.
5.) Search for a specific format (e.g. time)
Example: Search for a time in the format "HH:MM"
\d{2}:\d{2}
This searches for two digits, a colon and two digits again.
6.) Search for text in quotes
Example: Search for everything in quotes
".+?"
This matches the content between quotes. The .+? means "any text in minimal match".
7.) Search for a specific string with possible variations
Example: Search for "Q-Dir" or "Quad File Explorer"
Q-Dir|Quad File Explorer
The | stands for "or".
8.) Search for a string at the beginning of a line
Example: Search for a string that is at the beginning of the line
^Quad File Explorer
The ^ stands for the beginning of the line.
9.) Search for optional characters
Example: Search for "clock" or "clocks"
Clock?
The ? after the character means that the previous character is optional.
10.) List of the most important commands and symbols used in regular expressions
Here is a list of the most important commands and symbols used in regular expressions (regex) to search for text patterns:
1. Character classes
- . : Any character except newline.
- \d : Digit [0-9].
- \D : No digit character.
- \w : Alphanumeric character (letter, number, or underscore).
- \W : No alphanumeric character.
- \s : Whitespace character (tab, space, etc.).
- \S : No whitespace.
2. Repetitions
- * : 0 or more repetitions of the previous character.
- + : 1 or more repetitions of the previous character.
- ? : 0 or 1 repetition of the previous character (optional).
- {n} : Exactly n repetitions.
- {n,} : At least n repetitions.
- {n,m} : Between n and m repetitions.
3. Anchor (position in text)
- ^ : Start of line.
- $ : End of line.
- \b : Word boundary (e.g. \bbeste\b only matches the word "beste" and not "bestes").
- \B : No word boundary.
4. Groups and alternatives
- ( ... ) : Brackets for groupings and priority.
- | : Or (e.g. best|hardware finds "best" or "hardware").
- (?: ... ) : Non-capturing group (prevents the expression from being captured as a group).
5. Escaping
- \ : Escape character to use special characters like . or * as a literal (e.g. \. looks for a dot).
6. Lookahead and Lookbehind (Looking Forward and Backward)
- (?= ...) : Positive lookahead - checks if a pattern is followed without capturing it (e.g. (?=.*\bbest\b) checks if "best" occurs somewhere later in the line).
- (?! ...) : Negative lookahead – checks if a pattern does not follow (e.g. (?!.*bad) ensures that "bad" does not follow).
- (?<= ...) : Positive lookbehind – checks if a pattern is present before (e.g. (?<=\bbeste\b) ensures that "best" occurs before).
- (?<! ...) : Negative lookbehind – checks if a pattern is not present before.
- (?m) : Multiline mode – ^ and $ match the beginning and end of the line, not just the beginning and end of the entire text.
- (?s) : Dotall mode – the dot . also matches line breaks.
8. Examples
- \d{3}-\d{3}-\d{4} : Finds a phone number format like "123-456-7890".
- ^[A-Za-z]+$ : Finds a line that consists only of letters.
- \bhttps?://\S+ : Finds URLs that start with "http" or "https".
These commands will help you search virtually any type of text, from simple words to complex patterns. If you have any specific questions or use cases, let me know!
The procedure on a platform virtual machine, such as that used when working with virtual machines VMs or virtual environments e.g. cloud platforms, can
Everyone is familiar with opening the Character Map in Windows 11, 10, etc, but how do I use the Character Map on Microsofts Windows Desktop and Server
The icon cache / temporary storage under Windows can lead to incorrect shortcut icons, here is the solution for deleting / resetting the icon cache on Windows
The printer queue folder can be opened and viewed under Windows 11, 10, or MS Server OS in the file explorer, the open print jobs are saved here Contents:
In order to display SVG thumbnails in Windows Explorer under Windows 11, 10, and MS Server, a shell extension for the operating system is required Preface:
This website does not store personal data. However, third-party providers are used to display ads, which are managed by Google and comply with the IAB Transparency and Consent Framework (IAB-TCF). The CMP ID is 300 and can be individually customized at the bottom of the page. more Infos & Privacy Policy ....