How to remove text between brackets

Is there a transform that can remove all of the text between brackets. The data looks like this:-

1 Acacia Avenue, Anytown, Anyshire (AD4 0RG)

I want to remove the text that is in bold, ie. the brackets themselves plus everything in between. I can easily remove just the brackets, but not sure how to remove the text.

Thanks in advance for any suggestions.

Use Replace transform, set Match Type to Regex, replace \(.*\) with nothing.

This is the basic approach. More work would be needed for unmatched parentheses.

1 Like

You can use regular expression in the Replace transform.

Remove text in brackets.transform (2.3 KB)

Thank you, this works perfectly.

Aaaarghhh - some records have two sets of brackets. Which means everything between the first opening bracket and the second closing bracket, is removed.

(Rushden) Acacia Avenue, Anytown, Anyshire (AD4 0RG)

In the above example, everything is removed using the transform suggested.

Is there a way to force the removal of the text between brackets only if the closing bracket is the last character in the field?

UK housing data is so flaky!

Thanks again for any suggestions.

Try to add a space in front of the regex.
As I can see there is no space before the first “(“ at the start of the record.
But always at the end.

Thanks for your help and that is a great suggestion. Unfortunately, some of the records have multiple sets of brackets within the field.

What I want is to remove the postcode that is within brackets at the end of the field, but keep all other data within brackets.

Try non-greedy: \(.+?\)

Thanks for your help.

If anyone is looking to do something similar, I ended up using a bit of lateral thinking.

I filtered those records that ended in a postcode within brackets and then chopped the last 9 characters.

I then created a stack comprising this new filtered set plus the remaining records that did not end in a postcode within brackets.

I then removed all the remaining brackets and white space.

Using 9 characters to chop, definitely removes all of the postcode part and the closing bracket. In some cases it will leave the opening bracket and/or the space before that, but they are easily removed.

Thanks to those that offered help.

1 Like

If you wanted only to remove bracketed data at the end of the line, end the Regex with $ or start it with a space, or both.

Look at EDT documentation (Help>Easy Data Transform Help) under the Regex item where you will find links to some of the many helpful sites on the subject.

1 Like

Thanks for your suggestion, trying this now.

It might be possible to ask ChatGPD for a RegEx describing what shall be reached in as much detail as possible. Might be faster …. But for sure the sides linked in the docu are good

That is exactly what I did! And it is working perfectly now.

1 Like

Please share what worked, so other seeing the post can benefit from it. :slight_smile:

Try this for the regex:

([(].*[)])

Regex101.com is your friend.

1 Like

In the end, I used Chat GPT to help construct a Regex that removes only UK postcodes within brackets plus UK postcodes that are not within brackets: this is what worked:-

\s*\(?\s*\b[A-PR-UWYZ][A-HK-Y]?[0-9][A-Z0-9]?\s*[ \t\u00A0]?[0-9][ABD-HJLNP-UW-Z]{2}\b\s*\)?\s*

2 Likes

Thanks, I will investigate this for future reference although Chat GPT constructs complex Regexs that work perfectly!