regex
Whats the difference between sed -E and sed -e
From source code, -E is an undocumented option for compatibility with BSD sed. /* Undocumented, for compatibility with BSD sed. */ case ‘E’: case ‘r’: if (extended_regexp_flags) usage(4); extended_regexp_flags = REG_EXTENDED; break; And from manual, -E in BSD sed is used to support extended regular expressions.
Regex – Find all matching words that don’t begin with a specific prefix
Off the top of my head, you could try: \b # word boundary – matches start of word (?!girl) # negative lookahead for literal ‘girl’ \w* # zero or more letters, numbers, or underscores friend # literal ‘friend’ \b # word boundary – matches end of word Update Here’s another non-obvious approach which should work … Read more
Regex allow digits and a single dot
If you want to allow 1 and 1.2: (?<=^| )\d+(\.\d+)?(?=$| ) If you want to allow 1, 1.2 and .1: (?<=^| )\d+(\.\d+)?(?=$| )|(?<=^| )\.\d+(?=$| ) If you want to only allow 1.2 (only floats): (?<=^| )\d+\.\d+(?=$| ) \d allows digits (while \D allows anything but digits). (?<=^| ) checks that the number is preceded by … Read more
“UnicodeEncodeError: ‘ascii’ codec can’t encode character”
You’re trying to convert unicode to ascii in “strict” mode: >>> help(str.encode) Help on method_descriptor: encode(…) S.encode([encoding[,errors]]) -> object Encodes S using the codec registered for encoding. encoding defaults to the default encoding. errors may be given to set a different error handling scheme. Default is ‘strict’ meaning that encoding errors raise a UnicodeEncodeError. Other … Read more
How to make “grep” read patterns from a file?
grep -v -f pattern_file
Finding and removing Non-ASCII characters from an Oracle Varchar2
I think this will do the trick: SELECT REGEXP_REPLACE(COLUMN, ‘[^[:print:]]’, ”)
Private IP Address Identifier in Regular Expression
I’m assuming you want to match these ranges: 127. 0.0.0 – 127.255.255.255 127.0.0.0 /8 10. 0.0.0 – 10.255.255.255 10.0.0.0 /8 172. 16.0.0 – 172. 31.255.255 172.16.0.0 /12 192.168.0.0 – 192.168.255.255 192.168.0.0 /16 You are missing some dots that would cause it to accept for example 172.169.0.0 even though this should not be accepted. I’ve fixed … Read more
How to extract domain name from url?
You can use simple AWK way to extract the domain name as follows: echo http://example.com/index.php | awk -F[/:] ‘{print $4}’ OUTPUT: example.com 🙂