Uploaded image for project: 'YADE - Yet Another Data Exchange Tool'
  1. YADE - Yet Another Data Exchange Tool
  2. YADE-70

Implement "real" regular expression for settings "replace/replacing"

    XMLWordPrintable

Details

    Description

      Presently it is not possible to define a regexp-syntax on the "replacement" setting. Due to this it is not possible, to rearange the sequence, cut off parts of the value, discard parts of the name and so on.

      This improvement is made to allow all this functionalities.

      An Java-based example:

      <code>
      /**

      • simple textrecplacing: replace the full string
        */

      strReplaceWhat = "Hello";
      strReplaceWith = "World";
      strStringToWorkOn = "Hello";

      doTest("replace the full string", "Hello", "World", strStringToWorkOn, strReplaceWith);

      /**

      • simple example: replace the groups by absolute values
        */
        strReplaceWhat = "(1)abc(12)def(.*)";
        strReplaceWith = "A;BB;CCC";
        strStringToWorkOn = "1abc12def123.txt";

      doTest("replace the groups by absolute values", strReplaceWhat, strReplaceWith, strStringToWorkOn, "AabcBBdefCCC");

      strReplaceWhat = "(INT_)(.*)";
      // strReplaceWith = ";
      2";
      strReplaceWith = "\\-;
      2";
      strStringToWorkOn = "INT_4711-0815.txt";

      doTest("suppres the first part of the value", strReplaceWhat, strReplaceWith, strStringToWorkOn, "4711-0815.txt");

      /**

      • a little bit more complicated:
      • the first 5 and the last chars are part of the new string. the 6 chars in the middle are discarded.
      • the "non-standard" pattern - is used to indicate, that this group has to be discarded in the
      • resulting text. As an alternative it is possible to use an empty item ";;".
        */
        strReplaceWhat = "(. {5}

        )(.

        {6}

        )(.*)";
        // strReplaceWith = "\\1;\\-;
        3;";
        strReplaceWith = "\\1;;
        3;";
        strStringToWorkOn = "abcba123456hallo.txt";

      doTest("suppres the first part of the value", strReplaceWhat, strReplaceWith, strStringToWorkOn, "abcbahallo.txt");

      /**

      • An example for swapping the groups
        */
        doTest("Swapping", "(1)abc(12)def(.*)", "\\2;
        1;CCC", "1abc12def123.txt", "12abc1defCCC");

      /**

      • Delete a group at the end of the string
        */
        doTest("Swapping", "(1)abc(12)def(.*)", "\\2;\\1;
        -", "1abc12def123.txt", "12abc1def");

      /**

      • put a prefix to the new string-value
        */
        doTest("Prefix", "(.*)", "prefix
        1", "1abc12def123.txt", "prefix1abc12def123.txt");

      /**

      • a suffix is possible, too
        */
        doTest("Prefix", "(.*)", "
        1suffix", "1abc12def123.txt", "1abc12def123.txtsuffix");

      /**

      • a suffix and a prefix is possible. makes it more flexible
        */
        doTest("Prefix", "(.*)", "prefix
        1suffix", "1abc12def123.txt", "prefix1abc12def123.txtsuffix");

      /**

      • now we have a prefix with the value but we have to delete it on the result-value
        */
        doTest("Prefix", "(prefix)(.*)", "\\-;
        2", "prefix1abc12def123.txt", "1abc12def123.txt");

      /*

      • Introducing a "non-regexp" feature: date-variable.
      • The format has to be given as a valid java-daten-format mask.
      • */
        String strDate = SOSDate.getCurrentTimeAsString("yyyyMMddHHmm");
        doTest("Date insertion", "(.*)(.txt)", "\\1_[date:yyyyMMddHHmm];
        2", "1.txt", "1_" + strDate + ".txt");

      strDate = SOSDate.getCurrentTimeAsString();
      doTest("Date insertion without date-format", "(.*)(.txt)", "\\1_[date:];
      2", "1.txt", "1_" + strDate + ".txt");

      strDate = SOSDate.getCurrentTimeAsString();
      doTest("Date suffix", "(.*)(.txt)", "\\1;
      2_[date:]", "1.txt", "1.txt_" + strDate);

      strDate = SOSDate.getCurrentTimeAsString();
      doTest("Date prefix", "(.*)(.txt)", "[date:]_\\1;
      2", "1.txt", strDate + "_1.txt");

      </code>

      This code-snippet is part of the JUnit-Test sos.util.SOSFileOperationsTest.

      Affected classes: SOSFileOperations
      Documentation: /params/param_replacement.xml

      Attachments

        Activity

          People

            kb Klaus-Dieter Buettner (Inactive)
            kb Klaus-Dieter Buettner (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 2 days
                2d
                Remaining:
                Remaining Estimate - 2 days
                2d
                Logged:
                Time Spent - Not Specified
                Not Specified