Class ReplaceText

java.lang.Object
org.apache.nifi.components.AbstractConfigurableComponent
org.apache.nifi.processor.AbstractSessionFactoryProcessor
org.apache.nifi.processor.AbstractProcessor
org.apache.nifi.processors.standard.ReplaceText
All Implemented Interfaces:
org.apache.nifi.components.ConfigurableComponent, org.apache.nifi.processor.Processor

@SideEffectFree @SupportsBatching(defaultDuration=TWENTY_FIVE_MILLIS) @InputRequirement(INPUT_REQUIRED) @Tags({"Text","Regular Expression","Update","Change","Replace","Modify","Regex"}) @CapabilityDescription("Updates the content of a FlowFile by searching for some textual value in the FlowFile content (via Regular Expression/regex, or literal value) and replacing the section of the content that matches with some alternate value. It can also be used to append or prepend text to the contents of a FlowFile.") @SystemResourceConsideration(resource=MEMORY) @UseCase(description="Append text to the end of every line in a FlowFile",keywords={"raw text","append","line"},configuration="\"Evaluation Mode\" = \"Line-by-Line\"\n\"Replacement Strategy\" = \"Append\"\n\n\"Replacement Value\" is set to whatever text should be appended to the line.\nFor example, to insert the text `<fin>` at the end of every line, we would set \"Replacement Value\" to `<fin>`.\nWe can also use Expression Language. So to insert the filename at the end of every line, we set \"Replacement Value\" to `${filename}`\n") @UseCase(description="Prepend text to the beginning of every line in a FlowFile",keywords={"raw text","prepend","line"},configuration="\"Evaluation Mode\" = \"Line-by-Line\"\n\"Replacement Strategy\" = \"Prepend\"\n\n\"Replacement Value\" is set to whatever text should be prepended to the line.\nFor example, to insert the text `<start>` at the beginning of every line, we would set \"Replacement Value\" to `<start>`.\nWe can also use Expression Language. So to insert the filename at the beginning of every line, we set \"Replacement Value\" to `${filename}`\n") @UseCase(description="Replace every occurrence of a literal string in the FlowFile with a different value",keywords={"replace","string","text","literal"},configuration="\"Evaluation Mode\" = \"Line-by-Line\"\n\"Replacement Strategy\" = \"Literal Replace\"\n\"Search Value\" is set to whatever text is in the FlowFile that needs to be replaced.\n\"Replacement Value\" is set to the text that should replace the current text.\n\nFor example, to replace the word \"spider\" with \"arachnid\" we set \"Search Value\" to `spider` and set \"Replacement Value\" to `arachnid`.\n") @UseCase(description="Transform every occurrence of a literal string in a FlowFile",keywords={"replace","transform","raw text"},configuration="\"Evaluation Mode\" = \"Line-by-Line\"\n\"Replacement Strategy\" = \"Regex Replace\"\n\"Search Value\" is set to a regular expression that matches the text that should be transformed in a capturing group.\n\"Replacement Value\" is set to a NiFi Expression Language expression that references `$1` (in quotes to escape the reference name).\n\nFor example, if we wanted to lowercase any occurrence of WOLF, TIGER, or LION, we would use a \"Search Value\" of `(WOLF|TIGER|LION)` and a \"Replacement Value\" of `${\'$1\':toLower()}`.\nIf we want to replace any identifier with a hash of that identifier, we might use a \"Search Value\" of `identifier: (.*)` and a \"Replacement Value\" of `identifier: ${\'$1\':hash(\'sha256\')}`\n") @UseCase(description="Completely replace the contents of a FlowFile to a specific text",keywords={"replace","raw text"},configuration="\"Evaluation Mode\" = \"Entire text\"\n\"Replacement Strategy\" = \"Always Replace\"\n\n\"Replacement Value\" is set to the new text that should be written to the FlowFile. This text might include NiFi Expression Language to reference one or more attributes.\n") public class ReplaceText extends org.apache.nifi.processor.AbstractProcessor
  • Field Details

    • REPLACEMENT_NORMALIZATION_PATTERN

      private static final Pattern REPLACEMENT_NORMALIZATION_PATTERN
    • LINE_BY_LINE

      public static final String LINE_BY_LINE
      See Also:
    • ALL

      public static final String ALL
      See Also:
    • FIRST_LINE

      public static final String FIRST_LINE
      See Also:
    • EXCEPT_FIRST_LINE

      public static final String EXCEPT_FIRST_LINE
      See Also:
    • LAST_LINE

      public static final String LAST_LINE
      See Also:
    • EXCEPT_LAST_LINE

      public static final String EXCEPT_LAST_LINE
      See Also:
    • ENTIRE_TEXT

      public static final String ENTIRE_TEXT
      See Also:
    • prependValue

      public static final String prependValue
      See Also:
    • appendValue

      public static final String appendValue
      See Also:
    • surroundValue

      public static final String surroundValue
      See Also:
    • regexReplaceValue

      public static final String regexReplaceValue
      See Also:
    • literalReplaceValue

      public static final String literalReplaceValue
      See Also:
    • alwaysReplace

      public static final String alwaysReplace
      See Also:
    • SUBSTITUTE_VARIABLES_VALUE

      public static final String SUBSTITUTE_VARIABLES_VALUE
      See Also:
    • unescapedBackReferencePattern

      private static final Pattern unescapedBackReferencePattern
    • DEFAULT_REGEX

      private static final String DEFAULT_REGEX
      See Also:
    • DEFAULT_REPLACEMENT_VALUE

      private static final String DEFAULT_REPLACEMENT_VALUE
      See Also:
    • PREPEND

      static final org.apache.nifi.components.AllowableValue PREPEND
    • APPEND

      static final org.apache.nifi.components.AllowableValue APPEND
    • SURROUND

      static final org.apache.nifi.components.AllowableValue SURROUND
    • LITERAL_REPLACE

      static final org.apache.nifi.components.AllowableValue LITERAL_REPLACE
    • REGEX_REPLACE

      static final org.apache.nifi.components.AllowableValue REGEX_REPLACE
    • ALWAYS_REPLACE

      static final org.apache.nifi.components.AllowableValue ALWAYS_REPLACE
    • SUBSTITUTE_VARIABLES

      static final org.apache.nifi.components.AllowableValue SUBSTITUTE_VARIABLES
    • REPLACEMENT_STRATEGY

      public static final org.apache.nifi.components.PropertyDescriptor REPLACEMENT_STRATEGY
    • SEARCH_VALUE

      public static final org.apache.nifi.components.PropertyDescriptor SEARCH_VALUE
    • REPLACEMENT_VALUE

      public static final org.apache.nifi.components.PropertyDescriptor REPLACEMENT_VALUE
    • PREPEND_TEXT

      static final org.apache.nifi.components.PropertyDescriptor PREPEND_TEXT
    • APPEND_TEXT

      static final org.apache.nifi.components.PropertyDescriptor APPEND_TEXT
    • CHARACTER_SET

      public static final org.apache.nifi.components.PropertyDescriptor CHARACTER_SET
    • MAX_BUFFER_SIZE

      public static final org.apache.nifi.components.PropertyDescriptor MAX_BUFFER_SIZE
    • EVALUATION_MODE

      public static final org.apache.nifi.components.PropertyDescriptor EVALUATION_MODE
    • LINE_BY_LINE_EVALUATION_MODE

      public static final org.apache.nifi.components.PropertyDescriptor LINE_BY_LINE_EVALUATION_MODE
    • PROPERTY_DESCRIPTORS

      private static final List<org.apache.nifi.components.PropertyDescriptor> PROPERTY_DESCRIPTORS
    • REL_SUCCESS

      public static final org.apache.nifi.processor.Relationship REL_SUCCESS
    • REL_FAILURE

      public static final org.apache.nifi.processor.Relationship REL_FAILURE
    • RELATIONSHIPS

      private static final Set<org.apache.nifi.processor.Relationship> RELATIONSHIPS
    • replacementStrategyExecutor

      private ReplaceText.ReplacementStrategyExecutor replacementStrategyExecutor
  • Constructor Details

    • ReplaceText

      public ReplaceText()
  • Method Details

    • getSupportedPropertyDescriptors

      protected List<org.apache.nifi.components.PropertyDescriptor> getSupportedPropertyDescriptors()
      Overrides:
      getSupportedPropertyDescriptors in class org.apache.nifi.components.AbstractConfigurableComponent
    • getRelationships

      public Set<org.apache.nifi.processor.Relationship> getRelationships()
      Specified by:
      getRelationships in interface org.apache.nifi.processor.Processor
      Overrides:
      getRelationships in class org.apache.nifi.processor.AbstractSessionFactoryProcessor
    • customValidate

      protected Collection<org.apache.nifi.components.ValidationResult> customValidate(org.apache.nifi.components.ValidationContext validationContext)
      Overrides:
      customValidate in class org.apache.nifi.components.AbstractConfigurableComponent
    • setup

      @OnScheduled public void setup(org.apache.nifi.processor.ProcessContext context)
    • onTrigger

      public void onTrigger(org.apache.nifi.processor.ProcessContext context, org.apache.nifi.processor.ProcessSession session) throws org.apache.nifi.processor.exception.ProcessException
      Specified by:
      onTrigger in class org.apache.nifi.processor.AbstractProcessor
      Throws:
      org.apache.nifi.processor.exception.ProcessException
    • escapeLiteralBackReferences

      private static String escapeLiteralBackReferences(String unescaped, int numCapturingGroups)
    • normalizeReplacementString

      private static String normalizeReplacementString(String replacement)
      If we have a '$' followed by anything other than a number, then escape it. E.g., '$d' becomes '\$d' so that it can be used as a literal in a regex.