What is the difference between square brackets and parentheses in a regex?

These regexes are equivalent (for matching purposes): /^(7|8|9)\d{9}$/ /^[789]\d{9}$/ /^[7-9]\d{9}$/ The explanation: (a|b|c) is a regex “OR” and means “a or b or c”, although the presence of brackets, necessary for the OR, also captures the digit. To be strictly equivalent, you would code (?:7|8|9) to make it a non capturing group. [abc] is a … Read more

How to print variable in sml?

I’m new to SML and in debugging I usually print out the variable to see if it matches up to what I expected it should be. I would like to print out a variable within a functionwhat i have is this :function header.. Right now its printing the string product, but I would like to … Read more

In Python, how do I determine if an object is iterable?

Checking for __iter__ works on sequence types, but it would fail on e.g. strings in Python 2. I would like to know the right answer too, until then, here is one possibility (which would work on strings, too): from __future__ import print_function try: some_object_iterator = iter(some_object) except TypeError as te: print(some_object, ‘is not iterable’) The … Read more

Align an element to bottom with flexbox

You can use auto margins Prior to alignment via justify-content and align-self, any positive free space is distributed to auto margins in that dimension. So you can use one of these (or both): Show code snippet Alternatively, you can make the element before the a grow to fill the available space: Show code snippet

What is an method in Java? Can it be overridden?

Have a look at the Java Virtual Machine Specification, chapter 2.9. It say on the <init> name: At the level of the Java Virtual Machine, every constructor written in the Java programming language (JLS §8.8) appears as an instance initialization method that has the special name <init>. This name is supplied by a compiler. Because … Read more

How to enter a multi-line command

You can use a space followed by the grave accent (backtick): However, this is only ever necessary in such cases as shown above. Usually you get automatic line continuation when a command cannot syntactically be complete at that point. This includes starting a new pipeline element: will work without problems since after the | the … Read more

How to iterate through table in Lua?

To iterate over all the key-value pairs in a table you can use pairs: outputs: Edit: Note that Lua doesn’t guarantee any iteration order for the associative part of the table. If you want to access the items in a specific order, retrieve the keys from arr and sort it. Then access arr through the … Read more