Get Text from Regular Expression

Verb: getRegex

Gets from a text the snippets corresponding to the regular expression informed in the parameter Regular expression.

Syntax

getRegex --text(String) --regexPattern(String) [--regexOptions(DisplayableRegexOptions)] [--groupnumber(Numeric)] [--groupname(String)] [--getbyindex(Boolean)] --occurrenceindex(Numeric) (String)=value

Inputs

Script Designer Required AcceptedTypes Description
--text Text Required Text Text that should be analyzed to get the snippets matching the regular expression.
--regexPattern Regular expression Required Text Regular expression used to identify what should be gotten.
--regexOptions Options Optional DisplayableRegexOptions Regular expression options:
  • Compiled
  • Culture Invariant
  • ECMA Script
  • Explicit Capture
  • Ignore Case
  • Ignore Pattern Whitespace
  • Multiline
  • Right To Left
  • Singleline
  • --groupnumber Group Number Optional Number Group number of the regular expression from which the text is obtained.
    --groupname Group Name Optional Text Group name of the regular expression from which the text is obtained.
    --regex Regular expression(Obsolete) Optional Text Regular expression used to find matches.
    This parameter is obsolete, the Regular expression parameter should be used instead.
    --ignorecase Ignore case(Obsolete) Optional Boolean When enabled, specifies case-insensitive matching.
    This parameter is obsolete. To select regular expression options, use the Options instead.
    --dotmatchesnewline Dot matches new line(Obsolete) Optional Boolean When enabled, the dot (.) character matches every character, instead of every character except "\n".
    This parameter is obsolete. To select regular expression options, use the Options instead.
    --freespacing Ignore white space(Obsolete) Optional Boolean When enabled, eliminates blank spaces and breaks without adding a escape character.
    This parameter is obsolete. To select regular expression options, use the Options instead.
    --explicitcapture Explicit capture(Obsolete) Optional Boolean When enabled, specifies that the only valid captures are explicitly named or numbered groups of the form (? ).
    This parameter is obsolete. To select regular expression options, use the Options instead.
    --multiline Multiline(Obsolete) Optional Boolean When enabled, changes the meaning of ^ and $ so they match at the beginning and end, respectively, of any line, and not just the beginning and end of the entire string.
    This parameter is obsolete. To select regular expression options, use the Options instead.
    --getbyindex Get by index Optional Boolean Option that allows the search of the snippet by its index.
    --occurrenceindex Index Only whenGet by index is True Number Occurrence number of the pattern defined in the regular expression.

    Outputs

    Script Designer AcceptedTypes Description
    value Text gotten Text Returns the text snippet that matches the regular expression.

    Example

    Example 1: The Get Text from Regular Expression command is used to obtain the first occurrence of the regular expression "(^\w{5}) (\w{5})" returning all the contents of this occurrence..

    defVar --name inputText --type String --value "Hello world\r\nhello World\r\nHELLO WORLD"
    defVar --name gottenText --type String
    defVar --name regularExpression --type String --value "(^\\w{5}) (\\w{5})"
    // Finds the first occurrence of the regular expression "(^\\w{5}) (\\w{5})" and returns all the contents of this occurrence.getRegex --text "${inputText}" --regexPattern "${regularExpression}" --regexOptions "IgnoreCase, Multiline, CultureInvariant" gottenText=value
    getRegex --text "${inputText}" --regexPattern "${regularExpression}" --regexOptions "IgnoreCase, Multiline" gottenText=value
    logMessage --message "${gottenText}" --type "Info"
    // This example produces the following result:
    // Hello world
    

    Example 2: The Get Text from Regular Expression command is used to obtain the second occurrence of the regular expression "(^\w{5}) (\w{5})" returning the content corresponding to the second group of this occurrence.

    defVar --name inputText --type String --value "Hello world\r\nhello World\r\nHELLO WORLD"
    defVar --name gottenText --type String
    defVar --name regularExpression --type String --value "(^\\w{5}) (\\w{5})"
    // Finds the second occurrence of the regular expression "(^\\w{5}) (\\w{5})" and returns the content in the second group of this occurrence.
    getRegex --text "${inputText}" --regexPattern "${regularExpression}" --regexOptions "IgnoreCase, Multiline" --groupnumber 2 --getbyindex  --occurrenceindex 2 gottenText=value
    logMessage --message "${gottenText}" --type "Info"
    // This example produces the following result:
    // World
    

    Example 3: The Get Text from Regular Expression command is used to obtain the third occurrence of the regular expression "(? ^\w{5}) (? \w{5})" returning the content corresponding to the group with the name "helloGroup" of this occurrence .

    defVar --name inputText --type String --value "Hello world\r\nhello World\r\nHELLO WORLD"
    defVar --name gottenText --type String
    defVar --name regularExpression --type String --value "(?<helloGroup>^\\w{5}) (?<worldGroup>\\w{5})"
    // Finds the third occurrence of the regular expression "(?<helloGroup>^\\w{5}) (?<worldGroup>\\w{5})" and returns the existing content in the group with the name "helloGroup" of this occurrence.
    getRegex --text "${inputText}" --regexPattern "${regularExpression}" --regexOptions "IgnoreCase, Multiline" --groupname helloGroup --getbyindex  --occurrenceindex 3 gottenText=value
    logMessage --message "${gottenText}" --type "Info"
    // This example produces the following result:
    // HELLO
    

    Remarks

    The Regular expression parameter accepts several regular expression groups, so the search options can be divided into Group Number and Group Name.

    See Also

  • Add Escape Characters to Regular Expression
  • Add Escape Characters to Text
  • Calculate Hash
  • Change Text Case
  • Check File
  • Concatenate Texts
  • Convert HTML to Text
  • Count Occurrences in Text
  • Count Text Characters
  • Create Random Text
  • Create Table By Regular Expression
  • Empty or Null Text Variable
  • Find by Regular Expression
  • Find Occurrences in Text
  • Format Text
  • Get Subtext
  • HTML to Markdown
  • Insert New Line to Text
  • Join Text
  • Pad Text
  • Parse URI
  • Remove Diacritics
  • Remove Escape Characters
  • Replace Part of Text
  • Replace Text
  • Split Text
  • Trim Text Blanks