Xbasic

TAGGED_PATTERN Function

Syntax

Formatted_String as C = TAGGED_PATTERN(C tagged_input,C tagged_output,C String)

Arguments

tagged_input

A formatted string that identifies the tags of the Input_String and the characters that separate the tags. The general format of the Input_String is: Placeholder [ Input_Format_Characters ] Separator_Character Placeholder [ IInput_Format_Characters ] Separator_Character... The syntax for the Input_Format string is described below:

1-99

Placeholder for tagged elements (i.e. "fields"). "1" indicates first tagged element, "2" is second tagged element, and so on.

Input Format Characters

Allow you to refine the search process. This is useful when the formatting of the Input_String is irregular.

Separator Character

Typically, a non-alpha, non-numeric character. Also excluding "?", "*", "", and "".

Input Format Characters
Meaning
*

Wildcard - 0 to N characters. You cannot use "*" as a separator between elements. You must use "\*".

+ [ N ]

Match N or more characters. When N is missing, the expression means match 0 or more characters.

?

Single wildcard character. You cannot use "?" as a separator between elements. You must use "\?".

[]

Square brackets denote a set of characters.

^

Indicates characters that do not match.

a-z

Lowercase letters.

A-Z

Uppercase letters.

0-9

Numbers.

\

Escape character. Used in front of * ? or \ when you want to use these characters in the output_string.

tagged_output

A formatted string that identifies the new sequence of the tags of the Input_String and the new characters that separate the tags.

String

A character string.

Description

Perform tagged expression replacement on a string.

Discussion

TAGGED_PATTERN() parses the Input_String (into "tags", or "fields") using the format specified by the Input_Format string and creates a formatted character string based on the format specified by Output_Format. For example, assume that you have a string which contains the value: "John:Smith:Programmer". This string has three fields (or tags) separated by colons. The Input_Format string that corresponds with this string is "1:2:3". An Output_Format string of "2, 1: 3" would create a result string of "Smith, John: Programmer". The Output_Format string specifies field 2, then a comma and a space, then field 1, then a colon and a space, then field 3. Contrast the TAGGED_PATTERN() function with the WORD_TAGGED_PATTERN()function that operates on a string that is divided into multiple "words". This is typically a CR-LF delimited string in which the function operates on each "word" in the string. The following are examples of various Input_Format strings:

Example
Description
"1-2-3"

Tag 1 is composed of the characters up to the first encountered "-" character. Tag 2 is composed of the remaining characters up to the second "-". Tag 3 is composed of the remaining characters.

"1^a-zA-Z + 2"

Tag 1 is composed of alphabetic characters, breaking at the first non-alphabetic character. Tag 2 is composed of the first remaining alphabetic characters through the end of the string.

"1-/2-/3"

Tag 1 is composed of characters up to the first "-" or "/" character. Tag 2 is composed of remaining characters up to the second "-" or "/" character. Tag 3 is composed of the remaining characters.

Example 

This script parses and input string and creates a modified output string in an address format.

string = "Fred:Smith:123 Main Street:Boston:Ma:02116"
address = tagged_pattern("1:2:3:4:5:6","1 2~3~4,5 6",string)

now convert the "~" to carriage return-line feed.

address = stritran(address, "~", crlf() )
? address
= "Fred Smith
123 Main Street
Boston,Ma 02116"

This script parses a U.S format date (month, day, year) and outputs a European format date (day, month, year).

? tagged_pattern("1/2/3", "2-1-3", "2/29/00")
= "29-2-00"
? tagged_pattern("1A-Z2A-Z3", "2-1-3", "2A29B00")
= "29-2-00"
? tagged_pattern("1^0-92^0-93^0-9", "2-1-3", "2A29B00C")
= "29-2-00"

See Also