Tag Info

Hot answers tagged


\b means "word boundary" outside of character classes (also called character sets) and "backspace" inside character classes. Here it means a word boundary: \bhello\b Here it means a backspace [\b] See this Microsoft reference: Character Escapes in Regular Expressions. PERL regex has the same definition for \b.


How about #/usr/bin/env bash for f in * do [[ $f =~ [0-9]{4}_[0-9]{4}_[0-9]{2}_[0-9]{2} ]] || echo "File $f does not match" done The regular expression checks for any digit ([0-9]). The numbers in curly braces are the number of repetitions so [0-9]{4} will match any 4 digits. I would recommend you don't use bash for this but find instead. It ...


grep -o -n '[{}]' <filename> | cut -d : -f 1 | uniq -c The output will be something like: 3 1 1 2 Meaning 3 occurrences in the first line and 1 in the second. Taken from http://stackoverflow.com/a/15366097/3378354 .


Yes, you need to use \r instead of \n in the replacement part, a quirk of Vim's :s command. And you can further simplify the command by using a different separator, e.g. #, and by referring to the match via &: :186,$s# </tr>#<td></td> \r&#g


It’s clunky, but this should be very portable: #!/bin/sh for x in * do case "$x" in [0-9][0-9][0-9][0-9]_[0-9][0-9][0-9][0-9]_[0-9][0-9]_[0-9][0-9]) echo "$x matches" ;; *) echo "$x doesn’t match" esac done # And, to be annoyingly complete, for x in .* do echo "$x ...


Is using grep a requirement?  Here’s an alternative: sed 's/[^{}]//g' your_file | awk '{print NR, length }' The sed strips out all characters other than { and } (i.e., leaving only { and } characters), and then the awk counts the characters on each line (which are just the { and } characters).  To suppress lines with no matches, sed 's/[^{}]//g' ...


Following regex should work: protocol [^ ]+|HOST \d+\.\d+\.\d+\.\d+|PORT \d+ I'm using Sublime Text to test it, but it should work in Notepad++ too. Here's how it works: it's composed from three parts: protocol [^ ]+ HOST \d+\.\d+\.\d+\.\d+ PORT \d+ | symbol means that any of those parts can be matched. First part: protocol [^ ]+ protocol ...

Only top voted, non community-wiki answers of a minimum length are eligible