Being locked up in solitary confinement is enough to derang almost anyone. “It’s a standard psychiatric concept, if you put people in isolation, they will go insane.” Yet apparently there are those who survive while lacking any physical tokens of a hobby, or books, or conversation with others.
A very few are productive in solitary...
I wasn't going to write this. After all, I'd tried a simple regular expression in Oracle SQL then in Python. Since I'm still a rookie in regular expressions, (yes, even after 10 years, I use them only very occasionally) I had to re-ruminate on what I'd done. As one author wrote:
There is no gentle beginning to regular expressions. You are either into hieroglyphics big time - in which case you will love this stuff - or you need to use regular expressions, in which case your only reward may be a headache. But they are jolly useful. Sometimes.
I'm not hooked on hieroglyphics. I can barely decipher mathematical equations (makes being a programmer or engineering challenging).
After pondering, I realizing I'd overlooked the begin/end conditions. As I said: Unlike LIKE (cough, cough) there's an implicit "%" (in LIKE-speak) on both ends of the match, so I tried again in Oracle SQL. I call that implicit '%' the condition of being "unbookended." Why bother redoing it in Python? I was going to try another regular expression, but I'm stumped by the results of the "base case".
Quick recap. Here's the "unbookended" regular expression:
((LN-)?\d+-\d)|(PENDING)
In order to test the bookending, I used a more comprehensive test set; here are the Oracle results:
X MATCH_TRICK
888-7 match
007 ???
444-9 match
KILN-12345-1BAD match
LN-12345-1 match
PENDING match
PENDINGALING match
qwer444-9blah match
Now let's try the same thing in Python:
import re
y = "((LN-)?\d+-\d)|(PENDING)"
pattern = re.compile(y)
sample = [ "LN-12345-1"
, "KILN-12345-1BAD"
, "444-9"
, "qwer444-9blah"
, "PENDING"
, "PENDINGALING"
, " 888-7 "
, "007"
]
for element in sample:
matched = "match" if pattern.match(element) else "???"
print('{:<20} {:<5}'.format(element,matched))
Yes, I learned how to pad out the strings for clearer columnar output.
However, the results don't match my Oracle results:
LN-12345-1 match
KILN-12345-1BAD ???
444-9 match
qwer444-9blah ???
PENDING match
PENDINGALING match
888-7 ???
007 ???
Now I've got more ruminating ahead of me. It seems like the Python implementation differs from Oracle's for the base case. Hmm.
Some can be productive in solitary. One example:.
I hope it never happens to me; I'm more likely to just keep bouncing my head off the walls of a 6'x10' cell.
But it's inspiring to know that there's hope under even very trying circumstances.