Page 1 of 1

Regex Basics

Posted: Fri Aug 02, 2019 2:16 pm
by Support_Hans
A regular expression, commonly referred to as a "regex", is a pattern that can be used to search for and replace sets of characters in a given string of files. GoAnywhere supports the regex patterns available to the java.util.regex class.

Example: Given the string "abc.txt", a search pattern such as "(.*)\.txt" can be used to look for any string that matches this regex. This search pattern broken down is as follows:

- "(.*)" refers to any group of characters, with a group size 0 or greater.
- "\." is quoting the '.' character. '.' itself can refer to any character, as shown in the step above
- "txt" is that string itself

To summarize, the search pattern is looking for any file with the suffix ".txt".

A replace pattern "$1.csv" can be used to change the given string. This regex broken down is as follows:

-"$1" refers to the first captured group of the search pattern. In this case, the first captured group is "(.*)", or "abc" from the given string.
-".csv" will be changing the file suffix from ".txt".

To summarize, the replace pattern will be keeping the file name, but changing the file suffix to ".csv". The new string will be "abc.csv".

More information can be found in the Oracle Java Documentation. Oracle also provides Regular Expression tutorials that explain each construct with examples. Both of those links can be found below:

https://docs.oracle.com/javase/7/docs/a ... ttern.html
https://docs.oracle.com/javase/tutorial ... index.html

The User Guide of GoAnywhere MFT also provides a summary of regex constructs under the navigation "Appendix" > "Wildcards and Regular Expressions".