regex
Match empty lines in a file with ‘grep’
The regular expression to match the end of the line is $, not \n (since grep works a line at a time, it ignores the newlines between lines). grep -c ‘^$’ myfile.txt
regex with negative matching (ie, find string that _doesn’t_ match regex)
Use the :g! command to delete every line that doesn’t match. :g!/ERROR/d
regex matching alpha character followed by 4 alphanumerics
EDIT: Grrr… edited regex due to new “clarification” 🙂 ^[A-C][a-zA-Z0-9]{4}$ EDIT: To explain the above Regex in English… ^ and $ mean “From start to finish” (this ensures that the whole string must perfectly match) [A-C] means “Match either A, B, or C“ [a-zA-Z0-9]{4} means “Match 4 lower case letters, upper case letters, or numbers”
Find and replace with reordered date format in notepad++
You can do this with Textpad: Find: ([0-9]+)-+([0-9]+)-+([0-9]+) Replace: \3-\2-\1
Regex-based matching and sustitution with nano?
My version of nano has an option to swtich to regex search with the meta character + R. In cygwin on Windows, the meta-key is alt, so I hit ctrl+\ to get into search-and-replace mode, and then alt+r to swtich to regex search.
Regex get domain name from email
[^@] means “match one symbol that is not an @ sign. That is not what you are looking for – use lookbehind (?<=@) for @ and your (?=\.) lookahead for \. to extract server name in the middle: (?<=@)[^.]+(?=\.) The middle portion [^.]+ means “one or more non-dot characters”. Demo.
How do I create a regex in Emacs for exactly 3 digits?
If you’re entering the regex interactively, and want to use {3}, you need to use backslashes to escape the curly braces. If you don’t want to match any part of the longer strings of numbers, use \b to match word boundaries around the numbers. This leaves: \b[0-9]\{3\}\b For those wanting more information about \b, see … Read more
Regex – how to tell something NOT to match? [duplicate]
^(?!www\.petroules\.com$).*$ will match any string other than www.petroules.com. This is called negative lookahead. [^www\.petroules\.com] means “Match one character except w, p, e, t, r, o, u, l, s or dot”.
Regex to match anything
The regex .* will match anything (including the empty string, as Junuxx points out).