Tutorial by Examples

break statement When a break statement executes inside a loop, control flow "breaks" out of the loop immediately: i = 0 while i < 7: print(i) if i == 4: print("Breaking from loop") break i += 1 The loop conditional will not be evaluated a...
Standard Creation It is recommended to use this form only when creating regex from dynamic variables. Use when the expression may change or the expression is user generated. var re = new RegExp(".*"); With flags: var re = new RegExp(".*", "gmi"); With a backsl...
There are several flags you can specify to alter the RegEx behaviour. Flags may be appended to the end of a regex literal, such as specifying gi in /test/gi, or they may be specified as the second argument to the RegExp constructor, as in new RegExp('test', 'gi'). g - Global. Finds all matches inst...
Match Using .exec() RegExp.prototype.exec(string) returns an array of captures, or null if there was no match. var re = /([0-9]+)[a-z]+/; var match = re.exec("foo123bar"); match.index is 3, the (zero-based) location of the match. match[0] is the full match string. match[1] is the t...
var re = /[a-z]+/; if (re.test("foo")) { console.log("Match exists."); } The test method performs a search to see if a regular expression matches a string. The regular expression [a-z]+ will search for one or more lowercase letters. Since the pattern matches the string,...
The String object has the following methods that accept regular expressions as arguments. "string".match(... "string".replace(... "string".split(... "string".search(... Match with RegExp console.log("string".match(/[i-n]+/)); console.log(&...
git remote add upstream git-repository-url Adds remote git repository represented by git-repository-url as new remote named upstream to the git repository
Assuming you set the upstream (as in the "setting an upstream repository") git fetch remote-name git merge remote-name/branch-name The pull command combines a fetch and a merge. git pull The pull with --rebase flag command combines a fetch and a rebase instead of merge. git pull ...
To stage a file for committing, run git add <filename>
git add -A 2.0 git add . In version 2.x, git add . will stage all changes to files in the current directory and all its subdirectories. However, in 1.x it will only stage new and modified files, not deleted files. Use git add -A, or its equivalent command git add --all, to stage all ch...
You can make Git ignore certain files and directories — that is, exclude them from being tracked by Git — by creating one or more .gitignore files in your repository. In software projects, .gitignore typically contains a listing of files and/or directories that are generated during the build proces...
Changing the text of an existing UILabel can be done by accessing and modifying the text property of the UILabel. This can be done directly using String literals or indirectly using variables. Setting the text with String literals Swift label.text = "the new text" Objective-C // Do...
Setting a specific Seed will create a fixed random-number series: random.seed(5) # Create a fixed state print(random.randrange(0, 10)) # Get a random integer between 0 and 9 # Out: 9 print(random.randrange(0, 10)) # Out: 4 Resetting the seed will create the same &qu...
import java.awt.Image; import javax.imageio.ImageIO; ... try { Image img = ImageIO.read(new File("~/Desktop/cat.png")); } catch (IOException e) { e.printStackTrace(); }
Optionals are a generic enum type that acts as a wrapper. This wrapper allows a variable to have one of two states: the value of the user-defined type or nil, which represents the absence of a value. This ability is particularly important in Swift because one of the stated design objectives of the ...
x > y x < y These operators compare two types of values, they're the less than and greater than operators. For numbers this simply compares the numerical values to see which is larger: 12 > 4 # True 12 < 4 # False 1 < 4 # True For strings they will compare lexicographical...
x != y This returns True if x and y are not equal and otherwise returns False. 12 != 1 # True 12 != '12' # True '12' != '12' # False
x == y This expression evaluates if x and y are the same value and returns the result as a boolean value. Generally both type and value need to match, so the int 12 is not the same as the string '12'. 12 == 12 # True 12 == 1 # False '12' == '12' # True 'spam' == 'spam' # True 'spam' == ...
Use the import statement: >>> import random >>> print(random.randint(1, 10)) 4 import module will import a module and then allow you to reference its objects -- values, functions and classes, for example -- using the module.name syntax. In the above example, the random module...
Instead of importing the complete module you can import only specified names: from random import randint # Syntax "from MODULENAME import NAME1[, NAME2[, ...]]" print(randint(1, 10)) # Out: 5 from random is needed, because the python interpreter has to know from which resource it...

Page 32 of 1336