Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.



Excerpt
hiddentrue

replaceFirst(listToCheck, findPattern, replacementString) Replace the first occurrence of a pattern with a replacement string.


Function: replaceFirst()

Replace the first occurrence of a pattern with a replacement string.

...

ArgumentTypeDescription
listToCheckArrayList of strings to evaluate
findPatternRegular ExpressionPattern to be matched in listToCheck
replacementStringStringString to replace matching pattern in list

Examples

replaceFirst(in.fileName, "[0-9]{8}", "")

replaceFirst() removes the first string of 8 digits from file names contained in the attribute in.fileName.

If in.fileName = "20060712file-proc20070103-1263", this returns "file-proc20070103-1263".


replaceFirst(in.fileName, "file_([0-9A-Za-z]+)\\.txt", "$1")

replaceFirst() matches alphanumeric characters between "file_" and ".txt", and replaces the whole string with this value, if a match is made. In this way, a part or parts of the input string can be extracted. If in.fileName = "file_teamA.txt", the result of this expression will be "teamA".

...