通过正则表达式创建表
动词:getRegexTable
可从以下位置获取: <Standard>
使用包含正则表达式的文本来创建数据表。
语法
getRegexTable --text(String) --regexPattern(String) [--regexOptions(DisplayableRegexOptions)] (DataTable)=value (Numeric)=rows (Numeric)=columns
输入
| 脚本 | 设计器 | 必需的 | AcceptedTypes | Description |
|---|---|---|---|---|
| -- 文本 | 文本 | 必需的 | 文本 | 用于创建数据表的文本。 |
| --regexPattern | 正则表达式 | 必需的 | 文本 | 用于映射数据表值的正则表达式。 |
| --regexOptions | 选项 | 可选 | 可显示的正则表达式选项 | 正则表达式选项包括: |
输出
| 脚本 | 设计器 | AcceptedTypes | Description |
|---|---|---|---|
| 值 | 表 | 数据表 | 根据文本和正则表达式创建的数据表。 |
| 行 | 行 | 成员 | 命令执行中影响的行数。 |
| columns | 列数 | 成员 | 命令执行中影响的列数。 |
示例
使用正则表达式 "Name: (.+?)Security Number:\\s(\\d{11})" 创建基于在 Text 参数中输入的文本的数据表,以获取人员的姓名和社会保险号。
defVar --name dataTable --type DataTable
defVar --name amountLines --type Numeric
defVar --name columnCount --type Numeric
defVar --name currentLine --type Numeric
defVar --name IndexColumn --type String
defVar --name columnValue --type String
defVar --name column0 --type String
defVar --name column0Index --type String
defVar --name columnN1 --type String
defVar --name columnN1Index --type String
defVar --name columnN2 --type String
defVar --name columnN2Index --type String
// Create the data table based on the regular expression "Name: (. +?) CPF: \\ s (\\ d {11})".
getRegexTable --text "Name: Ana Alves Social Security Number: 22134567891, Name: Juliana Sanchez Social Security Number: 12332134554, Name: Paulo Lima Social Security Number: 45667878998, Name: Carlos Souza Social Security Number: 34567889000" --regexPattern "Name:(.+?)Social Security Number:\\s(\\d{11})" --regexOptions "Singleline" amountLines=rows columnCount=columns dataTable=value
logMessage --message "INDEX | VALUE | 0 | 0_INDEX | 1 | 1_INDEX | 2 | 2_INDEX" --type "Info"
for --variable ${currentLine} --from 1 --to ${dataTable.Rows} --step 1
// Maps and displays the values of the current table row
mapTableRow --dataTable ${dataTable} --row ${currentLine} --mappings "number=1=${IndexColumn},number=2=${columnValue},number=3=${column0},number=4=${column0Index},number=5=${columnN1},number=6=${columnN1Index},number=7=${columnN2},number=8=${columnN2Index}"
logMessage --message "${IndexColumn} | ${columnValue} | ${column0} | ${column0Index} | ${columnN1} | ${columnN1Index} | ${columnN2} | ${columnN2Index}" --type "Info"
next
logMessage --message "\r\nColumns affected: ${columnCount}\r\nLines affected: ${amountLines}" --type "Info"
// This example produces the following result:
// INDEX | VALUE | 0 | 0_INDEX | 1 | 1_INDEX | 2 | 2_INDEX
// 0 | Name: Ana Alves Social Security Number: 22134567891 | Name: Ana Alves Social Security Number: 22134567891 | 0 | Ana Alves | 5 | 22134567891 | 40
// 53 | Name: Juliana Sanchez Social Security Number: 12332134554 | Name: Juliana Sanchez Social Security Number: 12332134554 | 53 | Juliana Sanchez | 58 | 12332134554 | 99
// 112 | Name: Paulo Lima Social Security Number: 45667878998 | Name: Paulo Lima Social Security Number: 45667878998 | 112 | Paulo Lima | 117 | 45667878998 | 153
// 166 | Name: Carlos Souza Social Security Number: 34567889000 | Name: Carlos Souza Social Security Number: 34567889000 | 166 | Carlos Souza | 171 | 34567889000 | 209
// Columns affected: 8
// Lines affected: 4
备注
映射信息后,此命令遵循用于拆分表中信息的以下规则,返回表、行数、列数:
后续列基于部分匹配的值并遵循以下规则: