Skip to main content
Solved

Looping through string to remove known text


pauld
Contributor
Forum|alt.badge.img+1
  • Contributor

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.

 

View original
Did this help you find an answer to your question?

3 replies

geomancer
Evangelist
Forum|alt.badge.img+48
  • 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+48
  • 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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings