Contents:
Input can be specified as a column reference or a string literal, although string literal usage is rare.
- A column reference can refer to a column of String, Object, or Array type, which makes the
RIGHTFIND
function useful for filtering data before it has been completely un-nested into tabular data. - Starting location is specified from the end of the string.
- Returned value is from the beginning of the string, regardless of the string index value.
- If no match is found, the function returns a null value.
- If you need to determine if a value is in an array or not, you can use the
MATCHES
function, which returns a true/false response. See MATCHES Function.
You can also search a string from the left. For more information, see FIND Function.
Basic Usage
Column reference example:
derive type:single value: RIGHTFIND(MyName,'find this',true,0)
Output: Searches the MyName
column value for the last instance of the string find this
from the end of the value, ignoring case. If a match is found, the index value from the beginning of the string is written to the new column.
String literal example:
derive type:single value: RIGHTFIND('Hello, World','lo',false,2)
Output: Searches the string Hello, World
for the string lo
, in a case-sensitive search from the third-to-last character of the string. Since the match is found at the fourth character from the left, the value 3
is written to the new column.
If example:
derive type:single value: IF(RIGHTFIND(SearchPool,'FindIt') >= 0, 'found it', '') as: 'Finds'
Output: Searches the SearchPool
column value for the string FindIt
from the end of the value (default). Default behavior is to not ignore case. If the string is found, the new column Finds
contains the value found it
. Otherwise, the column is empty.
Syntax and Arguments
derive type:single value:RIGHTFIND(column_string,string_pattern,[ignore_case], [start_index])
Argument | Required? | Data Type | Description |
---|---|---|---|
column_string | Y | string | Name of the column or string literal to be applied to the function |
string_pattern | Y | string | String literal or pattern to find |
ignore_case | N | boolean | If true , a case-insensitive match is performed. Default is false . |
start_index | N | integer (non-negative) | If specified, this value identifies the start index value of the source data to search for a match. NOTE: This value is specified from the end of the string.
If not specified, the entire string is searched. |
For more information on syntax standards, see Language Documentation Syntax Notes.
column_string
Name of the item to be searched. Valid values can be:
- String literals must be quoted (
'Hello, World'
). - column reference to any type that can be inferred as a string, which encompasses all values.
Missing values generate the start-index parameter value.
- Multiple values and wildcards are not supported.
Usage Notes:
Required? | Data Type | Example Value |
---|---|---|
Yes | String literal or column reference (String, Array, or Object) | myColumn |
string_pattern
String literal or pattern to find. This value can be a string literal, a Alteryx® pattern, or a regular expression.
- Missing string or column values generate the start-index parameter value.
- String literals must be quoted (
'Hello, World'
).
- String literals must be quoted (
- Multiple values and wildcards are not supported.
Usage Notes:
Required? | Data Type | Example Value |
---|---|---|
Yes | String literal or pattern | 'Hello' |
ignore_case
If true
, the RIGHTFIND
function ignores case when trying to match the string literal or pattern value.
Default value is false
, which means that case-sensitive matching is performed by default.
Usage Notes:
Required? | Data Type | Example Value |
---|---|---|
No | Boolean | true |
start_index
The index of the character in the column or string literal value at which to begin the search, from the end of the string. For example, a value of 2
instructs the RIGHTFIND
function to begin searching from the third character in the column or string value.
NOTE: Index values begin at 0
. If not specified, the default value is 0
, which searches the entire string from the end of the string.
Value must be a non-negative integer value.
- If this value is greater than the length of the string, then no match is possible.
Usage Notes:
Required? | Data Type | Example Value |
---|---|---|
No | Integer (non-negative) | 2 |
Tip: For additional examples, see Common Tasks.
Examples
Example - Locate filenames in a URL
In this example, you must extract filenames from a column of URL values. Some rows do not have filenames, and there is some variation in the structure of the URLs.
Source:
URL |
---|
www.example.com |
http://www.example.com |
http://www.example.com/test_app |
http://www.example.com/index.html |
http://www.example.com/resources/mypic.jpg |
http://www.example.com/pages/mypage.html |
http://www.example.com/resources/styles.css |
www.example.com/resources/styles.css |
Transform:
To preserve the original column, you can use the following to create a working version of the source:
derive type:single value:URL as:'filename'
You can use the following to standardize the formatting of the working column:
replace: col:filename on:'http:' with:'' ignoreCase:true
Tip: You may need to modify the above to use a Alteryx pattern to also remove https://
.
The next two steps calcuate where in the filename
values the forward slash and dot values are located, if at all. The following calculates the
derive type:single value: RIGHTFIND(filename,"\/",true,0) as: 'rightFindSlash'
derive type:single value: RIGHTFIND(filename,".",true,0) as: 'rightFindDot'
If either of the above values is 0
, then there is no filename present:
set col:filename value:IF((rightFindSlash == 0) || (rightFindDot == 0), '', RIGHT(filename,(LEN(filename)-rightFindSlash)))
Results:
After removing the intermediate columns, you should end up with something like the following:
URL | filename |
---|---|
www.example.com | |
http://www.example.com | |
http://www.example.com/test_app | |
http://www.example.com/index.html | index.html |
http://www.example.com/resources/mypic.jpg | mypic.jpg |
http://www.example.com/pages/mypage.html | mypage.html |
http://www.example.com/resources/styles.css | styles.css |
www.example.com/resources/styles.css | styles.css |
This page has no comments.