3 ms·
Some regex APIs make the distinction between matching and searching. Matching means "is the entire input string accepted by this regular expression", and in thi
by Sharlin 5y ago
Some regex APIs make the distinction between matching and searching. Matching means "is the entire input string accepted by this regular expression", and in this sense the only input that matches the empty regex is the empty string. Searching, on the other hand, means "does the input string contain at least one substring accepted by this regular expression", and the empty string is the substring of every string. One can think of matching as searching with implicit ^ and $ anchors affixed to the regex.
- ruste 5y agoSurprisingly I've found this isn't quite true for match vs. search in python. You would think that searching using a regex starting with a ^ anchor might avoid scanning the whole string but it will do so anyway. It makes a huge performance difference if you miss it.
- bobbylarrybobby 5y agoCould it be looking for a match after every (potential) newline character?
- remram 5y agoOnly if you enable the MULTILINE flag.