Skip to main content

I have a field Filename where the naming convention is usually 2025 May Report.xlsx or 2025 January Report.xlsx

 

I have used the filenamepart extractor transformer to fetch the filename along with a string searcher transformer just to extract the year and month  from the filename. 

Now I want to create an additional field where I can flip the year and month -→ Month Year. How can i build the regex to achieve this? 

Also I might be expecting different scenarios where January is written as Jan, JAN or january

You might find it easier to split the filename using spaces as separators.

You can do this with the AttributeSplitter transformer.

Then, in an AttributeCreator, you can build your new field by combining _list{1} _list{0}.


Hi ​@aashnaparikh ,

I agree that using AttributeSplitter would be easier in this case, but of course StringSearcher can also be used to extract year and month from filename. Take a look into how you can use the All Matches List Name parameter or the Subexpression Matches List Name parameter in the transformer.

The screenshot below illustrates an example of All Matches List Name parameter use.

 


For what it's worth, you can also use StringReplacer to replace filename with "{month} {year}" directly, if you don't need to keep filename as an attribute.

StringReplacer parameters setting example:

  • Mode: Replace Regular Expression
  • Text To Replace: ^(\S)+\s+(\S+)\s+.+
  • Replacement Text: \2 \1

Reply