Skip to main content
Solved

I have a record formatted as follows

  • August 5, 2022
  • 6 replies
  • 24 views

Forum|alt.badge.img
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?

Best answer by markatsafe

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

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

6 replies

Forum|alt.badge.img+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


ebygomm
Influencer
Forum|alt.badge.img+46
  • Influencer
  • August 5, 2022

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(?=(?:[^\']*'[^\']*\')*[^\']*$)

 


ebygomm
Influencer
Forum|alt.badge.img+46
  • Influencer
  • August 5, 2022

@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


ebygomm
Influencer
Forum|alt.badge.img+46
  • Influencer
  • August 5, 2022

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 


Forum|alt.badge.img+2
  • Best Answer
  • August 5, 2022

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


Forum|alt.badge.img
  • Author
  • August 8, 2022

Thanks All!

@Mark Stoakes​ @ebygomm​ that works a treat