Regular Expression (Regex)
Regular Expression (Regex) is like a powerful search tool. It helps you find patterns in text. Think of it as a supercharged version of "find" in a text editor.
-
Literal characters match themselves.
-
Special characters and wildcards match various patterns.
-
Combining these can help you find almost anything in a text.
Using Regex
You can use Regex to find words in your file and folder names, by simply entering the words. No expression needed. Note that Regex is case sensitive.
Imagine you want to find all instances of "cat" or "dog" in a sentence.
You can use a regex: cat|dog
This will match "cat" in "I have a cat" and "dog" in "I have a dog".
Use https://regex101.com/ to evaluate your regex to confirm how it will behave in 3Sixty
Basic Building Blocks
-
1. Literal Characters: These are just normal characters that match themselves.
-
Example: abc matches "abc" in the text.
-
-
2. Wild cards and Special Characters:
-
[^] Negates a character set
Example [^0-9] Matches any character that is not a digit (0-9)
-
. Matches any single character.
Example: a.c matches "abc", "a3c", "a-c".
-
* Matches zero or more of the previous character.
Example: a* matches "", "a", "aa", "aaa".
-
[] Matches any one of the characters inside the brackets.
Example: [abc] matches "a", "b", or "c".
-
^ Matches the start of a string.
Example: ^a matches "a" at the start of the string.
-
$ Matches the end of a string.
Example: a$ matches "a" at the end of the string.
-
| Acts like an OR.
Example: cat|dog matches "cat" or "dog".
-
Simple Examples
-
Find "cat" in text:
-
Regex: cat
-
Matches: "The cat is cute."
-
-
Find any character between "c" and "t":
-
• Regex: c.t
-
• Matches: "cat", "cot", "cut"
-
-
Find "cat" at the beginning:
-
Regex: ^cat
-
Matches: "cat is cute."
-
-
Find "cat" at the end:
-
Regex: cat$
-
Matches: "I have a cat."
-
-
Find "a" zero or more times followed by "b":
-
Regex: a*b
-
Matches: "b", "ab", "aab"
-
-
Find "a", "b", or "c":
-
Regex: [abc]
-
Matches: "apple", "bat", "cat"
-
Complex Examples
Alphanumeric example:
The pattern for alphanumeric characters is [a-zA-Z0-9] or use \w as a shortcut. If you wish to include underscores simply add the carat to the list in the brackets [a-zA-Z0-9_]
To search for non-alphanumeric characters, add the carat (^) before the pattern ^[a-zA-Z0-9] The character simply translates to "Not", so it negates whatever is after it.
Clearing unwanted spaces example:
The pattern \s is regex shorthand for "spaces". If you're worried about tabs, line breaks etc. add an asterisk (*) after the pattern for what is called "greedy" selection.
Adding this as your regex and setting the replacement as ''
Related Links