Skip to main content
Solved

Looping through string to remove known text

  • April 25, 2024
  • 3 replies
  • 158 views

pauld
Contributor
Forum|alt.badge.img+1

Hi.

I have another string replacer question.

I have a file of text strings (appellation) similar to LOT 1/2 DP 17528 LOT 1/2 DP 13552 RS 16932 18812 19986/7 PT 18813 20862  BLK IV KAPUNATIKI SD

I have split the LOT 1/2 DP 17528LOT 1/2 DP 13552 into 4 separate rows

Temp, _result, appellation

LOT 1/2 DP 17528, LOT 1 DP 17528, appellation

LOT 1/2 DP 17528, LOT 2 DP 17528, appellation

LOT 1/2 DP 13552, LOT 1 DP 13552, appellation

LOT 1/2 DP 13552, LOT 2 DP 13552, appellation

 

What I want to be able to do is remove the temp part from appellation  The resultant appellation in this example would be: RS 16932 18812 19986/7 PT 18813 20862  BLK IV KAPUNATIKI SD

I have tried doing this but only ended up removing one part from each instead of both Temp parts.

 

I would be very grateful for any help with this.

Regards, Paul

Best answer by geomancer

You can use a StringReplacer in 'Replace Regular Expression’ mode.

For the data you provided the regular expression LOT 1/2 DP \d+  would work (the literal string 'LOT ½ DP ’ - this string ends in a space - followed by one or more digits, followed by a space).

But depending on the rest of your data, you will probably have to change the expression.

 

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.

3 replies

geomancer
Evangelist
Forum|alt.badge.img+60
  • Evangelist
  • Best Answer
  • April 25, 2024

You can use a StringReplacer in 'Replace Regular Expression’ mode.

For the data you provided the regular expression LOT 1/2 DP \d+  would work (the literal string 'LOT ½ DP ’ - this string ends in a space - followed by one or more digits, followed by a space).

But depending on the rest of your data, you will probably have to change the expression.

 


geomancer
Evangelist
Forum|alt.badge.img+60
  • Evangelist
  • April 25, 2024

In your example the string you want to remove always forms the first 8 words of the string.

You can use a StringReplacer to remove the first 8 words with the regular expression ^(\S+\s){8} (from the start of the string, find one or more non-whitespace characters followed by one whitespace character, and this 8 times).

 


pauld
Contributor
Forum|alt.badge.img+1
  • Author
  • Contributor
  • April 26, 2024

Thank you @geomancer . 

That was simpler than I was making it to be!

Regards, Paul