Skip to main content
Question

How to remove square brackets in a column?

  • November 14, 2018
  • 10 replies
  • 301 views

Hi everyone,

I looked up at some forum posts, I saw people excluding the content within squarebrackets with square brackets itself or deleting some funny characters, but I couldn't really find something which suit my situation or I just didn't understand the forum posts quite well.

The case is, I have got a column with strings such as "[]" or "[Park5, Park4]" and ideally I would like to remove the square brackets. I tried it with the stringreplacer with the regualr expression, however that didn't work, it has to be said that I am not that familiar with regular expression, so the way how I formulated it, might be wrong. In my case, I want to keep the content within the square brackets, while only deleting the square brackets itself.

 

Thank very much in advance!

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.

10 replies

david_r
Celebrity
  • 8394 replies
  • November 14, 2018

Try text to replace

\[(.*)\]

Replacement text

\1

ebygomm
Influencer
Forum|alt.badge.img+44
  • Influencer
  • 3429 replies
  • November 14, 2018

You could also use a string pair replacer, with the following replacement pairs

[ "" ] ""

 


  • Author
  • 8 replies
  • November 14, 2018

Try text to replace

\[(.*)\]

Replacement text

\1

@david_r   thank you very much for the formulation of the regular expression,

however I have another issue. It appeared afterwards that the comma in the [Park5, Park4]"  for example led to some problems when importing into another software, therefore, the comma preferably should also be deleted. I know vaguely that the ^ character is involved, however I have not really a clue how to formalate that 


david_r
Celebrity
  • 8394 replies
  • November 14, 2018

You could also use a string pair replacer, with the following replacement pairs

[ "" ] ""

 

This is a good one. Added bonus: easy to modify to get rid of the comma as well.


ebygomm
Influencer
Forum|alt.badge.img+44
  • Influencer
  • 3429 replies
  • November 14, 2018

You could also use a string pair replacer, with the following replacement pairs

[ "" ] ""

 

To replace the comma too, use [ "" ] "" , ""

Unfortunately the stringpairreplacer is not very legible when replacing single characters like this. You can vote for my improvement idea here https://knowledge.safe.com/idea/81295/stringpairreplacer-interface-improvements.html

 


  • Author
  • 8 replies
  • November 14, 2018

You could also use a string pair replacer, with the following replacement pairs

[ "" ] ""

 

@egomm wow that is a nice alternative, Is it possible to include symbols? I would like to add parentheses around a number for example, thus Park5 will become Park(5) or should I use the StringReplacer for that?


david_r
Celebrity
  • 8394 replies
  • November 14, 2018

@egomm wow that is a nice alternative, Is it possible to include symbols? I would like to add parentheses around a number for example, thus Park5 will become Park(5) or should I use the StringReplacer for that?

I suspect you'll need the StringSearcher for that one, as the StringPairReplacer is about replacing known characters. You can try this:

Text to replace:

(\d+)

Replacement text:

(\1)

  • Author
  • 8 replies
  • November 14, 2018

I suspect you'll need the StringSearcher for that one, as the StringPairReplacer is about replacing known characters. You can try this:

Text to replace:

(\d+)

Replacement text:

(\1)

@ david_r , for some reason after doing all the steps mentioned before

1) deleting square brackets in stringpairreplacer

2) deleting comma's in stringpairreplacer

3) and surrounding parentheses around the numbers in stringreplacer

I get the following output in the other software when I importing the column,

0684Q00000ArNNeQAN.png

 

0684Q00000ArNNZQA3.png

The square brackets in this case, is due to the fact that I am reading the column in the software as lists, therefore the squarebrackets. If I didn't remove the squarebrackets beforehand in FME, there would have been list in another list. 

However as you can see, instead of 'Park(5)','Park(4)' I get thus the thing above in the picture. So I was wondering how I could prevent the seperate entities as in the above picture


ebygomm
Influencer
Forum|alt.badge.img+44
  • Influencer
  • 3429 replies
  • November 14, 2018

@ david_r , for some reason after doing all the steps mentioned before

1) deleting square brackets in stringpairreplacer

2) deleting comma's in stringpairreplacer

3) and surrounding parentheses around the numbers in stringreplacer

I get the following output in the other software when I importing the column,

 

The square brackets in this case, is due to the fact that I am reading the column in the software as lists, therefore the squarebrackets. If I didn't remove the squarebrackets beforehand in FME, there would have been list in another list.

However as you can see, instead of 'Park(5)','Park(4)' I get thus the thing above in the picture. So I was wondering how I could prevent the seperate entities as in the above picture

What format are you writing to? It sounds like something that's being inserted on writing and may be controlled by a parameter in the writer. I presume if you hook up an inspector to the stringreplacer and look at the attributes they don't have the quote marks?


  • Author
  • 8 replies
  • November 14, 2018

What format are you writing to? It sounds like something that's being inserted on writing and may be controlled by a parameter in the writer. I presume if you hook up an inspector to the stringreplacer and look at the attributes they don't have the quote marks?

@egomm Yes when I look at inspector, there areindeed no quotation marks. When I delete the square brackets and the comma, then this problem doesn't occure. It's only after including the parentheses, that this does occur. In case when it has to do with a parameter in the writer, do you have by any chance an idea about which parameter it might be the case?