Learn After Effects Expressions 1.1 course is heavily focused on the basics of Expressions. Understanding the core of Expressions will give you a very strong foundation to build on. Contrary to popular belief, you don’t need to be great at math and you don’t need to know everything about Expressions in order to be good at them. ExpressionSuite Software. ExpressionSuite Software is a free, easy-to-use data-analysis tool that utilizes the comparative Cτ (ΔΔCτ) method to rapidly and accurately quantify relative gene expression across a large number of genes and samples. Aug 20, 2015 This video screencast was created with Doceri on an iPad. Doceri is free in the iTunes app store. Learn more at http://www.doceri.com. A) Write down the decimal 1.5 divided by 1: 1.5 = 1.51. B) Multiply both top and bottom by 10 for every number after the decimal point. (For example, if there are two numbers after the decimal point, then use 100, if there are three then use 1000, etc.) 1.51 = 1510. Note: 1510 is called a decimal fraction.
-->Quantifiers specify how many instances of a character, group, or character class must be present in the input for a match to be found. The following table lists the quantifiers supported by .NET.
Greedy quantifier | Lazy quantifier | Description |
---|---|---|
* | *? | Match zero or more times. |
+ | +? | Match one or more times. |
? | ?? | Match zero or one time. |
{ n} | { n}? | Match exactly n times. |
{ n,} | { n,}? | Match at least n times. |
{ n, m} | { n, m}? | Match from n to m times. |
The quantities
n
and m
are integer constants. Ordinarily, quantifiers are greedy; they cause the regular expression engine to match as many occurrences of particular patterns as possible. Appending the ?
character to a quantifier makes it lazy; it causes the regular expression engine to match as few occurrences as possible. For a complete description of the difference between greedy and lazy quantifiers, see the section Greedy and Lazy Quantifiers later in this topic.Important
Nesting quantifiers (for example, as the regular expression pattern
(a*)*
does) can increase the number of comparisons that the regular expression engine must perform, as an exponential function of the number of characters in the input string. For more information about this behavior and its workarounds, see Backtracking.Regular Expression Quantifiers
The following sections list the quantifiers supported by .NET regular expressions.
Note
If the *, +, ?, {, and } characters are encountered in a regular expression pattern, the regular expression engine interprets them as quantifiers or part of quantifier constructs unless they are included in a character class. To interpret these as literal characters outside a character class, you must escape them by preceding them with a backslash. For example, the string
*
in a regular expression pattern is interpreted as a literal asterisk ('*') character.Match Zero or More Times: *
The
*
quantifier matches the preceding element zero or more times. It is equivalent to the {0,}
quantifier. *
is a greedy quantifier whose lazy equivalent is *?
.The following example illustrates this regular expression. Of the nine digits in the input string, five match the pattern and four (
95
, 929
, 9219
, and 9919
) do not.The regular expression pattern is defined as shown in the following table.
Pattern | Description |
---|---|
b | Start at a word boundary. |
91* | Match a '9' followed by zero or more '1' characters. |
9* | Match zero or more '9' characters. |
b | End at a word boundary. |
Match One or More Times: +
The
+
quantifier matches the preceding element one or more times. It is equivalent to {1,}
. +
is a greedy quantifier whose lazy equivalent is +?
.For example, the regular expression
ban+w*?b
tries to match entire words that begin with the letter a
followed by one or more instances of the letter n
. The following example illustrates this regular expression. The regular expression matches the words an
, annual
, announcement
, and antique
, and correctly fails to match autumn
and all
.The regular expression pattern is defined as shown in the following table.
Pattern | Description |
---|---|
b | Start at a word boundary. |
an+ | Match an 'a' followed by one or more 'n' characters. |
w*? | Match a word character zero or more times, but as few times as possible. |
b | End at a word boundary. |
Match Zero or One Time: ?
The
?
quantifier matches the preceding element zero or one time. It is equivalent to {0,1}
. ?
is a greedy quantifier whose lazy equivalent is ??
.For example, the regular expression
ban?b
tries to match entire words that begin with the letter a
followed by zero or one instances of the letter n
. In other words, it tries to match the words a
and an
. The following example illustrates this regular expression.The regular expression pattern is defined as shown in the following table.
Pattern | Description |
---|---|
b | Start at a word boundary. |
an? | Match an 'a' followed by zero or one 'n' character. |
b | End at a word boundary. |
Match Exactly n Times: {n}
The
{
n}
quantifier matches the preceding element exactly n times, where n is any integer. {
n}
is a greedy quantifier whose lazy equivalent is {
n}?
.For example, the regular expression
bd+,d{3}b
tries to match a word boundary followed by one or more decimal digits followed by three decimal digits followed by a word boundary. The following example illustrates this regular expression.The regular expression pattern is defined as shown in the following table.
Pattern | Description |
---|---|
b | Start at a word boundary. |
d+ | Match one or more decimal digits. |
, | Match a comma character. |
d{3} | Match three decimal digits. |
b | End at a word boundary. |
Match at Least n Times: {n,}
The
{
n,}
quantifier matches the preceding element at least n times, where n is any integer. {
n,}
is a greedy quantifier whose lazy equivalent is {
n,}?
.For example, the regular expression
bd{2,}bD+
tries to match a word boundary followed by at least two digits followed by a word boundary and a non-digit character. The following example illustrates this regular expression. The regular expression fails to match the phrase '7 days'
because it contains just one decimal digit, but it successfully matches the phrases '10 weeks and 300 years'
.The regular expression pattern is defined as shown in the following table.
Pattern | Description |
---|---|
b | Start at a word boundary. |
d{2,} | Match at least two decimal digits. |
b | Match a word boundary. |
D+ | Match at least one non-decimal digit. |
Match Between n and m Times: {n,m}
The
{
n,
m}
quantifier matches the preceding element at least n times, but no more than m times, where n and m are integers. {
n,
m}
is a greedy quantifier whose lazy equivalent is {
n,
m}?
.In the following example, the regular expression
(00s){2,4}
tries to match between two and four occurrences of two zero digits followed by a space. Note that the final portion of the input string includes this pattern five times rather than the maximum of four. However, only the initial portion of this substring (up to the space and the fifth pair of zeros) matches the regular expression pattern.Match Zero or More Times (Lazy Match): *?
The
*?
quantifier matches the preceding element zero or more times, but as few times as possible. It is the lazy counterpart of the greedy quantifier *
.In the following example, the regular expression
bw*?oow*?b
matches all words that contain the string oo
.The regular expression pattern is defined as shown in the following table.
Pattern | Description |
---|---|
b | Start at a word boundary. |
w*? | Match zero or more word characters, but as few characters as possible. |
oo | Match the string 'oo'. |
w*? | Match zero or more word characters, but as few characters as possible. |
b | End on a word boundary. |
Match One or More Times (Lazy Match): +?
The
+?
quantifier matches the preceding element one or more times, but as few times as possible. It is the lazy counterpart of the greedy quantifier +
.For example, the regular expression
bw+?b
matches one or more characters separated by word boundaries. The following example illustrates this regular expression.Match Zero or One Time (Lazy Match): ??
The
??
quantifier matches the preceding element zero or one time, but as few times as possible. It is the lazy counterpart of the greedy quantifier ?
.For example, the regular expression
^s*(System.)??Console.Write(Line)??(??
attempts to match the strings 'Console.Write' or 'Console.WriteLine'. The string can also include 'System.' before 'Console', and it can be followed by an opening parenthesis. The string must be at the beginning of a line, although it can be preceded by white space. The following example illustrates this regular expression.The regular expression pattern is defined as shown in the following table.
Pattern | Description |
---|---|
^ | Match the start of the input stream. |
s* | Match zero or more white-space characters. |
(System.)?? | Match zero or one occurrence of the string 'System.'. |
Console.Write | Match the string 'Console.Write'. |
(Line)?? | Match zero or one occurrence of the string 'Line'. |
(?? | Match zero or one occurrence of the opening parenthesis. |
Match Exactly n Times (Lazy Match): {n}?
The
{
n}?
quantifier matches the preceding element exactly n
times, where n is any integer. It is the lazy counterpart of the greedy quantifier {
n}
.In the following example, the regular expression
b(w{3,}?.){2}?w{3,}?b
is used to identify a Web site address. Note that it matches 'www.microsoft.com' and 'msdn.microsoft.com', but does not match 'mywebsite' or 'mycompany.com'.The regular expression pattern is defined as shown in the following table.
Pattern | Description |
---|---|
b | Start at a word boundary. |
(w{3,}?.) | Match at least 3 word characters, but as few characters as possible, followed by a dot or period character. This is the first capturing group. |
(w{3,}?.){2}? | Match the pattern in the first group two times, but as few times as possible. |
b | End the match on a word boundary. |
Match at Least n Times (Lazy Match): {n,}?
The
{
n,}?
quantifier matches the preceding element at least n
times, where n is any integer, but as few times as possible. It is the lazy counterpart of the greedy quantifier {
n,}
.See the example for the
{
n}?
quantifier in the previous section for an illustration. The regular expression in that example uses the {
n,}
quantifier to match a string that has at least three characters followed by a period.Mechanical Expressions 1.1.11
Match Between n and m Times (Lazy Match): {n,m}?
The
{
n,
m}?
quantifier matches the preceding element between n
and m
times, where n and m are integers, but as few times as possible. It is the lazy counterpart of the greedy quantifier {
n,
m}
.In the following example, the regular expression
b[A-Z](w*?s*?){1,10}[.!?]
matches sentences that contain between one and ten words. It matches all the sentences in the input string except for one sentence that contains 18 words.The regular expression pattern is defined as shown in the following table.
Pattern | Description |
---|---|
b | Start at a word boundary. |
[A-Z] | Match an uppercase character from A to Z. |
(w*?s*?) | Match zero or more word characters, followed by one or more white-space characters, but as few times as possible. This is the first capture group. |
{1,10} | Match the previous pattern between 1 and 10 times. |
[.!?] | Match any one of the punctuation characters '.', '!', or '?'. |
Greedy and Lazy Quantifiers
A number of the quantifiers have two versions:
- A greedy version.A greedy quantifier tries to match an element as many times as possible.
- A non-greedy (or lazy) version.A non-greedy quantifier tries to match an element as few times as possible. You can turn a greedy quantifier into a lazy quantifier by simply adding a
?
.
Consider a simple regular expression that is intended to extract the last four digits from a string of numbers such as a credit card number. The version of the regular expression that uses the
*
greedy quantifier is b.*([0-9]{4})b
. However, if a string contains two numbers, this regular expression matches the last four digits of the second number only, as the following example shows.The regular expression fails to match the first number because the
*
quantifier tries to match the previous element as many times as possible in the entire string, and so it finds its match at the end of the string.This is not the desired behavior. Instead, you can use the
*?
lazy quantifier to extract digits from both numbers, as the following example shows.In most cases, regular expressions with greedy and lazy quantifiers return the same matches. They most commonly return different results when they are used with the wildcard (
.
) metacharacter, which matches any character.Quantifiers and Empty Matches
The quantifiers
*
, +
, and {
n,
m}
and their lazy counterparts never repeat after an empty match when the minimum number of captures has been found. This rule prevents quantifiers from entering infinite loops on empty subexpression matches when the maximum number of possible group captures is infinite or near infinite.For example, the following code shows the result of a call to the Regex.Match method with the regular expression pattern
(a?)*
, which matches zero or one 'a' character zero or more times. Note that the single capturing group captures each 'a' as well as String.Empty, but that there is no second empty match, because the first empty match causes the quantifier to stop repeating.To see the practical difference between a capturing group that defines a minimum and a maximum number of captures and one that defines a fixed number of captures, consider the regular expression patterns
(a1|(?(1)1)){0,2}
and (a1|(?(1)1)){2}
. Both regular expressions consist of a single capturing group, which is defined as shown in the following table.Pattern | Description |
---|---|
(a1 | Either match 'a' along with the value of the first captured group … |
|(?(1) | … or test whether the first captured group has been defined. (Note that the (?(1) construct does not define a capturing group.) |
1)) | If the first captured group exists, match its value. If the group does not exist, the group will match String.Empty. |
The first regular expression tries to match this pattern between zero and two times; the second, exactly two times. Because the first pattern reaches its minimum number of captures with its first capture of String.Empty, it never repeats to try to match
a1
; the {0,2}
quantifier allows only empty matches in the last iteration. In contrast, the second regular expression does match 'a' because it evaluates a1
a second time; the minimum number of iterations, 2, forces the engine to repeat after an empty match.See also
-->A Power Query M formula language query is composed of formula expression steps that create a mashup query. A formula expression can be evaluated (computed), yielding a value. The let expression encapsulates a set of values to be computed, assigned names, and then used in a subsequent expression that follows the in statement. For example, a let expression could contain a Source variable that equals the value of Text.Proper() and yields a text value in proper case.
Let expression
In the example above, Text.Proper('hello world') is evaluated to 'Hello World'.
The next sections describe value types in the language.
Primitive value
A primitive value is single-part value, such as a number, logical, text, or null. A null value can be used to indicate the absence of any data.
Type | Example value |
---|---|
Binary | 00 00 00 02 // number of points (2) |
Date | 5/23/2015 |
DateTime | 5/23/2015 12:00:00 AM |
DateTimeZone | 5/23/2015 12:00:00 AM -08:00 |
Duration | 15:35:00 |
Logical | true and false |
Null | null |
Number | 0, 1, -1, 1.5, and 2.3e-5 |
Text | 'abc' |
Time | 12:34:12 PM |
Function value
![Expression Expression](/uploads/1/2/5/6/125602599/944084682.jpg)
A Function is a value which, when invoked with arguments, produces a new value. Functions are written by listing the function’s parameters in parentheses, followed by the goes-to symbol =>, followed by the expression defining the function. For example, to create a function called “MyFunction” that has two parameters and performs a calculation on parameter1 and parameter2:
This code produces the value of 3.
Structured data values
The M language supports the following structured data values:
Note
Structured data can contain any M value. To see a couple of examples, see Additional structured data examples.
List
A List is a zero-based ordered sequence of values enclosed in curly brace characters { }. The curly brace characters { } are also used to retrieve an item from a List by index position. See [List value](#_List_value).
Note
Power Query M supports an infinite list size, but if a list is written as a literal, the list has a fixed length. For example, {1, 2, 3} has a fixed length of 3.
![Expressions Expressions](/uploads/1/2/5/6/125602599/607933871.jpg)
The following are some List examples.
Value | Type |
---|---|
{123, true, 'A'} | List containing a number, a logical, and text. |
{1, 2, 3} | List of numbers |
{ {1, 2, 3}, {4, 5, 6} } | List of List of numbers |
{ [CustomerID = 1, Name = 'Bob', Phone = '123-4567'], [CustomerID = 2, Name = 'Jim', Phone = '987-6543'] } | List of Records |
{123, true, 'A'}{0} | Get the value of the first item in a List. This expression returns the value 123. |
{ {1, 2, 3}, {4, 5, 6} }{0}{1} | Get the value of the second item from the first List element. This expression returns the value 2. |
Record
A Record is a set of fields. A field is a name/value pair where the name is a text value that is unique within the field’s record. The syntax for record values allows the names to be written without quotes, a form also referred to as identifiers. An identifier can take the following two forms:
- identifier_name such as OrderID.
- #'identifier name' such as #'Today's data is: '.
The following is a record containing fields named 'OrderID', 'CustomerID', 'Item', and 'Price' with values 1, 1, 'Fishing rod', and 100.00. Square brace characters [ ] denote the beginning and end of a record expression, and are used to get a field value from a record. The follow examples show a record and how to get the Item field value.
Here's an example record:
To get the value of an Item, you use square brackets as Source[Item]:
Table
A Table is a set of values organized into named columns and rows. The column type can be implicit or explicit. You can use #table to create a list of column names and list of rows. A Table of values is a List in a List. The curly brace characters { } are also used to retrieve a row from a Table by index position (see Example 3 – Get a row from a table by index position).
Example 1 - Create a table with implicit column types
Example 2 – Create a table with explicit column types
Both of the examples above creates a table with the following shape:
OrderID | CustomerID | Item | Price |
---|---|---|---|
1 | 1 | Fishing rod | 100.00 |
2 | 1 | 1 lb. worms | 5.00 |
Example 3 – Get a row from a table by index position
This expression returns the follow record:
OrderID | 2 |
CustomerID | 1 |
Item | 1 lb. worms |
Price | 5 |
Additional structured data examples
Structured data can contain any M value. Here are some examples:
Example 1 - List with [Primitive](#_Primitive_value_1) values, [Function](#_Function_value), and [Record](#_Record_value)
Evaluating this expression can be visualized as:
Example 2 - Record containing Primitive values and nested Records
Evaluating this expression can be visualized as:
Note
Although many values can be written literally as an expression, a value is not an expression. For example, the expression 1 evaluates to the value 1; the expression 1+1 evaluates to the value 2. This distinction is subtle, but important. Expressions are recipes for evaluation; values are the results of evaluation.
If expression
The if expression selects between two expressions based on a logical condition. For example:
The first expression (2 + 2) is selected if the logical expression (2 > 1) is true, and the second expression (1 + 1) is selected if it is false. The selected expression (in this case 2 + 2) is evaluated and becomes the result of the if expression (4).