What to do when a regular expression pattern doesn’t match anywhere in a string?

Oh Yes You Can Use Regexes to Parse HTML! For the task you are attempting, regexes are perfectly fine! It is true that most people underestimate the difficulty of parsing HTML with regular expressions and therefore do so poorly. But this is not some fundamental flaw related to computational theory. That silliness is parroted a … Read more

regular expressions: match x times OR y times

^(\d{3}|\d{6})$ You have to have some sort of terminator otherwise \d{3} will match 1234. That’s why I put ^ and $ above. One alternative is to use lookarounds: (?<!\d)(\d{3}|\d{6})(?!\d) to make sure it’s not preceded by or followed by a digit (in this case). More in Lookahead and Lookbehind Zero-Width Assertions.

Regexp for subdomain

Subdomain According to the pertinent internet recommendations (RFC3986 section 2.2, which in turn refers to: RFC1034 section 3.5 and RFC1123 section 2.1), a subdomain (which is a part of a DNS domain host name), must meet several requirements: Each subdomain part must have a length no greater than 63. Each subdomain part must begin and … Read more

explain gitignore pattern matching

Firstly the tricky part in your question is the first line in the .gitignore file: * // Says exclude each and every file in the repository, // unless I specify with ! pattern explicitly to consider it First we will consider the first version of your .gitignore. * exclude every file in the repository. !*.html … Read more

Invert match with regexp [duplicate]

Okay, I have refined my regular expression based on the solution you came up with (which erroneously matches strings that start with ‘test’). ^((?!foo).)*$ This regular expression will match only strings that do not contain foo. The first lookahead will deny strings beginning with ‘foo’, and the second will make sure that foo isn’t found … Read more

How can I match spaces with a regexp in Bash?

Replace: regexp=”templateUrl:[\s]*'” With: regexp=”templateUrl:[[:space:]]*'” According to man bash, the =~ operator supports “extended regular expressions” as defined in man 3 regex. man 3 regex says it supports the POSIX standard and refers the reader to man 7 regex. The POSIX standard supports [:space:] as the character class for whitespace. The GNU bash manual documents the … Read more