Text Filters

Text filters enable you to transform and manipulate text.

  • addslashes - Adds a backslash to certain special characters

  • capitalize - Converts the first letter of each word to a capital letter.

  • concat - Concatenates two values together.

  • contains - Returns whether or not the expression is found.

  • convert_encoding - Converts a text element's encoding to another

  • detect_encoding - Returns the encoding of a text element

  • ends_with - Returns whether or not the expression is present at the end.

  • icontains - Returns whether or not the case-insensitive expression is found.

  • iends_with - Returns whether or not the case-insensitive expression is present at the end.

  • iindex - Returns the index of the case-insensitive expression or false if it can't be found.

  • index - Returns the index of the case-sensitive expression or false if it can't be found.

  • istarts_with - Returns whether or not the case-insensitive expression is present at the beginning.

  • list_encodings - Returns available encoding formats for convert_encoding and detect_encoding

  • ltrim - Trim whitespace or other characters from the left side and return the result.

  • querystring_parse - Parses a query string from a URL into its individual key-value pairs.

  • regex_get_all_matches - Return all matches performed by a regular expression on the supplied subject text.

  • regex_get_first_match - Return the first set of matches performed by a regular expression on the supplied subject text.

  • regex_matches - Tests if a regular expression matches the supplied subject text.

  • regex_quote - Update the supplied text value to be properly escaped for regular expressions.

  • regex_replace - Perform a regular expression search and replace on the supplied subject text.

  • replace - Replace a text phrase with another.

  • rtrim - Trim whitespace or other characters from the right return the result.

  • split - Splits text into an array of text and returns the result.

  • sprintf - formats text with variable substitution.

  • starts_with - Returns whether or not the expression is present at the beginning.

  • strlen - Returns the number of characters.

  • substr - Extracts a section of text.

  • to_lower - Converts all characters to lower case and returns the result.

  • to_upper - Converts all characters to upper case and returns the result.

  • trim - Trim whitespace or other characters from both sides and return the result.

  • url_addarg - Parses a URL and returns an updated version with an encoded version of the supplied argument.

  • url_delarg - Parses a URL and returns an updated version with the supplied argument removed.

  • url_getarg - Gets the argument's value from a URL.

  • url_hasarg - Returns the existence of a argument in the URL.

  • strip_html - Parses through raw HTML and removes tags

  • url_parse - Parses a URL into its individual components.

addslashes:

Adds a backslash to the following characters: single quote, double quote, backslash, and null character.

capitalize:

Converts the first letter of each word to a capital letter.

concat:

Concatenates 2 text strings together by an optional separator. The value can be any text and the separator can be anything: + , -, _, a space, etc...

contains:

Returns whether or not the expression is found and is case-sensitive. The search term can be any string of text. This returns a "true" or "false" response.

convert_encoding

Converts an encoded text element from one type of encoding to another

detect_encoding

Detects the encoding of a text element. Use the Encodings parameter to specify the encodings to check against, or leave blank to auto-detect

ends_with:

Returns whether or not the expression is present at the end. The search term can be any string of text. This returns a "true" or "false" response.

icontains:

Returns whether or not the case-insensitive expression is found. The search term can be any string of text. This returns a "true" or "false" response.

iends_with:

Returns whether or not the case-insensitive expression is present at the end. The search term can be any string of text. This returns a "true" or "false" response.

iindex:

Returns the index of the case-insensitive expression or false if it can't be found. The search term can be any string of text. This returns an integer value of where the character(s) exist in the string. The first character in a text string has an index of 0.

index:

Returns the index of the case-sensitive expression or false if it can't be found. The search term can be any string of text. This returns an integer value of where the character(s) exist in the string. The first character in a text string has an index of 0.

istarts_with:

Returns whether or not the case-insensitive expression is present at the beginning. The search term can be any string of text. This returns a "true" or "false" response.

list_encodings

Lists the available encodings for detect_encoding and convert_encoding

ltrim:

Trim whitespace or other characters from the left side and return the result. The mask text can be any string of text.

rtrim:

Trim whitespace or other characters from the right return the result. The mask text can be any string of text.

querystring_parse:

Extracts query strings from a URL and places them into separate key/value pairs. The example below separates a URL using the url_parse filter, and then uses querystring_parse to parse the query parameters into separate keys and values.

join:

Joins an array of text into text via the separator and returns the result. Theseperator text can be any string of text. The array in this example is: [ hello, world, how, are, you]

Regex (Regular Expression)

Regex or regular expression is a more advance topic that can be useful for finding patterns in text. It is a string of text that allows you to create patterns that help match, locate, and manage text.

Regex typically includes something called delimiters to set the boundaries of the expression. Often times, / will be used as delimiters but almost any character can be used.

Regex filters inside the Query All Records function do not use delimiters.

Regex filters in any other variable, function, etc. in Xano require delimiters (meaning you'll need to wrap your expression in / characters) as shown in the below examples.

Regex uses special characters, for example:

. is any character
\d is any number
\s is any whitespace
\w is any word character
* means 0 or more
+ means 1 or more

Regex uses additional special characters, these are just to name a few as an example.

Some special characters need the \ escape character, which is why regex_quote can be useful to determine this. For example, . and $ do but @ does not.

You can then use ( ) to group matches. For example:

/(\w+)@\w+\.\w+/ this would get name of and full email address


/ is the starting delimiter
(\w+) is a matching group, this group must be at least 1 or more word character
@ is the symbold @
\w+ is at least 1 or more word character
\. is the symbol .
\w+ is at least 1 or more word character
/ is the ending delimiter

regex_get_all_matches:

Return all matches performed by a regular expression on the supplied subject text.

regex_get_first_match:

Return the first set of matches performed by a regular expression on the supplied subject text.

regex_matches:

Tests if a regular expression matches the supplied subject text. Returns a true or false boolean.

regex_quote:

Update the supplied text value to be properly escaped for regular expressions.

regex_replace

Perform a regular expression search and replace on the supplied subject text.

replace:

Replace a text phrase with another. Search can be any word in the value and the replacement can be anything.

split:

Splits text into an array of text and returns the result. The separator can be anything the words are separated by, in this example, it is the + symbol.

Split and trim text into an array example

We can combine multiple filters to format a text string into an array.

For example, we have the string "a , b,c, d"

Notice the inconsistent spaces. If all we do is use split then the spaces will persist in the array. We can combine trim and filter_empty filters to remove unnecessary spaces or blank values.

sprintf

Formats text with variable substitution. This is helpful when wanting to substitute a URL string with a variable that either the use provides or that is gotten from the result of a previous function. - %d is used to replace a number and will enforce a number. - %s is used to replace text.

The first example shows how to use variable substitution with a number using %d.

The second example will replace %s with text:

We can use multiple arguments on the sprintf filter to replace any number of values. In the example below we have 2 %d and 2 %s. The first %d is equivalent to the first argument of 123. The second %d is equivalent to the second argument of 789. The first %s is equivalent to the first argument of hi. The first %s is equivalent to the second argument of end.

If you have a % character in your text that you would NOT like to replace with the sprintf filter you are able to escape the filter by adding an additional % character next to the existing % character. "Example: "%%"

starts_with:

Returns whether or not the expression is present at the beginning. The search term can be any string of text and is case-sensitive. This returns a "true" or "false" response.

strlen:

Returns the number of characters.

strip_accents

Removes accents from characters

substr:

Extracts a section of text. The start pos is based on the # of characters from the beginning with the first char pos= 0. The length can be an int.

to_lower

Converts all characters to lower case and returns the result.

to_upper:

Converts all characters to upper case and returns the result.

trim:

Trim whitespace or other characters from both sides and return the result. The mask text can be any string of text.

url_addarg:

Parses a URL and returns an updated version with an encoded version of the supplied parameter. This filter is used to add a key(blog_id, authorname) and a value (123 , john). Those parameters would be added as ?blog_id=123 and ?authorname=john.

url_delarg:

Parses a URL and returns an updated version with the supplied parameter removed. This filter is used to delete a key(blog_id, authorname). Those parameters would be deleted at the end of a url as ?blog_id or ?authorname.

url_getarg:

Returns the value of a query parameter in a URL.

url_hasarg:

Returns the existence of an arguments in the URL.

strip_html:

Parses raw HTML and removes HTML tags, returning the remaining text.

For example, if you input HTML that contains a collection of <p> tags and want to remove these and only return the text. Good to use in succession with the split filter to parse several elements and separate them into an array.

url_parse:

Parses a URL into its individual components.

Last updated