Solved

I have a record formatted as follows


Badge
nID='1' nOperTime='2022-07-31 23:51:56' szUserName='default' EventType='Save Config' Remarks='Saved -P2P- config.IP:Local LoginUsername:default Group Name:user' 

I want to split this into nID, nOperTime, szUserName and EventType

 

I've tried using the KeyValueAttributeCreator transformer to do this with:-

 

Key,Value Delimiter: =

Key,Value Separator: <a single space>

 

After this runs I see thousands of columns created with name 1,2,3,4... which appear to be the value of nID rather than the key. I wonder if the issue is the quotes and if so is there a solution that will see quoted fields as a single value?

icon

Best answer by markatsafe 5 August 2022, 22:22

View original

6 replies

Badge +2

@davebarter​ There's a StringSearcher regex solution here but I can't see it:

(\\w+='[\\d\\-\\s:]+' )

gets the first name/value (nID='1' ), but I can't see how to make the sub-expression to repeat for subsequent name value pairs. If someone can figure out how todo that then the StringSearcher with Subexpression List Name will give you what you need I think

Userlevel 1
Badge +21

If you use a string replacer with some regex to replace all the spaces outside of quotes with pipe | or similar you can use that as the Delimiter int he KeyValueAttributeCreator transformer

 

think this regex should work

\s(?=(?:[^\']*'[^\']*\')*[^\']*$)

 

Userlevel 1
Badge +21

@davebarter​ There's a StringSearcher regex solution here but I can't see it:

     (\w+='[\d\-\s:]+' )

gets the first name/value (nID='1' ), but I can't see how to make the sub-expression to repeat for subsequent name value pairs.  If someone can figure out how todo that then the StringSearcher with Subexpression List Name will give you what you need I think

If you wanted to use this approach to get a list you could use this regex

(\w+\=\'[^\']+\'?)

Which would give you each element as a list value

image

Userlevel 1
Badge +21

If you don't need the process to be dynamic and always know the value of your keys you could also do something like thisimage 

Badge +2

@davebarter​ Thanks @ebygomm​ for the clever regex. I've attached an example workspace based on that approach. FME 2021.2

Badge

Thanks All!

@Mark Stoakes​ @ebygomm​ that works a treat

Reply