RegExp match repeated characters
You can match that with: (\w)\1*
You can match that with: (\w)\1*
As you identified and Wiktor mentioned, COUNTIF only supports wildcards. There are many ways to do what you want, though. To name two: =ArrayFormula(SUM(–REGEXMATCH(E9:E13, “50-03[123][012]*”))) =COUNTA(FILTER(E9:E13, REGEXMATCH(E9:E13, “50-03[123][012]*”)))
You can use guards: match a: case _ if a < 42: print(‘Less’) case _ if a == 42: print(‘The answer’) case _ if a > 42: print(‘Greater’) Another option, without guards, using pure pattern matching: match [a < 42, a == 42]: case [True, False]: print(‘Less’) case [_, True]: print(‘The answer’) case [False, False]: … Read more
You need to compile all your regex functions. Check this example: import re re1 = r’\d+\.\d*[L][-]\d*\s[A-Z]*[/]\d*’ re2 = ‘\d*[/]\d*[A-Z]*\d*\s[A-Z]*\d*[A-Z]*’ re3 = ‘[A-Z]*\d+[/]\d+[A-Z]\d+’ re4 = ‘\d+[/]\d+[A-Z]*\d+\s\d+[A-Z]\s[A-Z]*’ sentences = [string1, string2, string3, string4] for sentence in sentences: generic_re = re.compile(“(%s|%s|%s|%s)” % (re1, re2, re3, re4)).findall(sentence)
I really see no reason to use any external libraries for this, I’ve done this sort of thing many times and the following algorithm works quite well. I’ll assume that if you’re comparing two images that they have the same dimensions, but you can just resize one if they don’t. badness := 0.0 For x, … Read more
I don’t think you can (easily) use regex for the first case. The second case is easy though: Pattern pattern = Pattern.compile(“([a-z\\d])\\1\\1”, Pattern.CASE_INSENSITIVE); Since \\1 represents part matched by group 1 this will match any sequence of three identical characters that are either within the range a-z or are digits (\d). Update To be clear, … Read more
As explained by Neal Gafter from Microsoft: The reason it doesn’t work is that there is no conversion (explicit or implicit) defined from T to KeepalivePacket. Pattern matching requires such a conversion to exist, as it is defined in terms of the cast operator, which requires a conversion exist. The language specification and compiler agree … Read more
When you say let 5 = 10 it’s not a redefinition of 5, it’s a pattern matching, the same which occurs when you say foo 5 = undefined … foo 10 … The pattern simply fails if it’s ever matched. In let-expressions the match is lazy. This means the match is only being done when … Read more
The way you usually convert a &str to a String is to_owned, e.g. “me”.to_owned() However, you can’t do pattern matching on a String. You could expect a success, get a &str from the String then pattern match on that: fn player_starts() -> bool { println!(“Who will start (me/you)”); loop { let input = readline::readline(“>”); match … Read more
Only parameters in the first parameter section are considered for equality and hashing. scala> case class Foo(a: Int)(b: Int) defined class Foo scala> Foo(0)(0) == Foo(0)(1) res0: Boolean = true scala> Seq(0, 1).map(Foo(0)(_).hashCode) res1: Seq[Int] = List(-1669410282, -1669410282) UPDATE To expose b as a field: scala> case class Foo(a: Int)(val b: Int) defined class Foo … Read more