Skip to main content

I have a block of text separated by newline characters, e.g:

Some Text

Some More Text

Even More Text

PERIOD: 01/01/1990 TO 12/12/2020

What I'm attempting to do using regex is grab the entire line of text preceding the row beginning with PERIOD (i.e. "Even More Text"). In an online regex editor, the following expression successfully returns just the line containing "Even More Text":

^.*$(?=\\nPERIOD)

However, when I attempt to do the same in FME, it returns all lines above PERIOD. It seems as though in online editors the . includes all characters except newlines, whereas in FME it includes them? Is there a way to adjust multiline regex flags (or some other workaround) in FME to get the desired output?

Quantifiers are by definition greedy, matching as much as possible. By putting a ? behind your asterisk, it makes the quantifier lazy, matching as little as possible.

I don't know if it'll work, but try

^.*?$(?=\nPERIOD)

Why not use the AttributeSplitter to split the block of text by line, then send it to the ListExploder to process each line at a time. You can then use e.g. the AttributeCreator and the Adjacent feature mode to retrieve the previous line from the one you're processing:


You could use the regex to match everything but a newline

^r^\n]*(?=\nPERIOD)

But I would probably go with adjacent attribute mapping as mentioned by @david_r


You could use the regex to match everything but a newline

^r^\n]*(?=\nPERIOD)

But I would probably go with adjacent attribute mapping as mentioned by @david_r

Thank you. This regex returns the correct line I was after.


Why not use the AttributeSplitter to split the block of text by line, then send it to the ListExploder to process each line at a time. You can then use e.g. the AttributeCreator and the Adjacent feature mode to retrieve the previous line from the one you're processing:

Thanks David. This is an elegant alternative to using regex. Though it requires a few more transformers it might be preferable doing it this way to make the workbenches more usable for work colleagues.


Reply