Discussion:
Checking a match for numbers
@lbutlr
2017-08-17 17:13:48 UTC
Permalink
I want to check the contents of a variable for "too many" numbers

I'm sure there's a clever way with a weighted or match

something along the lines of "more than 4 numbers and more than 20% of the characters"

(A lot of mailers are now polluting the list-ID header with bullshit, and I want to detect that so I can discard the list-ID when it's garbage)
--
Apple broke AppleScripting signatures in Mail.app, so no random signatures.
David W. Tamkin
2017-08-23 18:53:42 UTC
Permalink
Post by @lbutlr
I want to check the contents of a variable for "too many" numbers
I'm sure there's a clever way with a weighted or match
something along the lines of "more than 4 numbers and more than 20% of the characters"
Let's see ...

# If the number of digits is more than 4, continue and don't skip.
:0
* 1^1 VARIABLE ?? [0-9]
* -4^0
{
# Fetch previous score and add back 4 to get digit count again;
# then subtract 1/5 the length of the variable.
:0
* $=^0
* 4^0
* -.2^1 VARIABLE ?? .
action
}
@lbutlr
2017-08-29 01:15:24 UTC
Permalink
Post by David W. Tamkin
# If the number of digits is more than 4, continue and don't skip.
:0
* 1^1 VARIABLE ?? [0-9]
* -4^0
{
# Fetch previous score and add back 4 to get digit count again;
# then subtract 1/5 the length of the variable.
:0
* $=^0
* 4^0
* -.2^1 VARIABLE ?? .
action
}
That looks good. Hadn't thought about a fractional score.
--
Apple broke AppleScripting signatures in Mail.app, so no random signatures.
udi M
2017-08-24 08:20:41 UTC
Permalink
Post by @lbutlr
I want to check the contents of a variable for "too many" numbers
I'm sure there's a clever way with a weighted or match
something along the lines of "more than 4 numbers and more than 20% of the characters"
(A lot of mailers are now polluting the list-ID header with bullshit, and I want to detect that so I can discard the list-ID when it's garbage)
Start with this two following hints. The 20% must be simple too - but
I have
math-phobia to figure out the score recipe.

(Note: maybe the score will not give you *_exactly_* 20%)

0:
* 1^1 .
{ all_chars=$= }

0:
* -4^0
* 1^1 [0-9]
{ more_then4="yes" }


--udi
Loading...