Skip to main content

Hi.

I have a file of text strings that have multiple ‘parts’ that I have split into a _list. 

Example text string...

  •  LOT 9 DP 19723 LOT 12 DP 384274 LOT 8 DP 30287 LOT 9 DP 2402 PT RS 17343 17491 BLK VII X XI TENGAWAI SD-TIMBER NOT ASSESSED

Using string searcher, I have formed a list of the formatted string to push into the list using regex: (LOT \d+ DP \d+){1,}

The result is a list containing the:

  • appellation:LOT 9 DP 19723 LOT 12 DP 384274 LOT 8 DP 30287 LOT 9 DP 2402 PT RS 17343 17491 BLK VII X XI TENGAWAI SD-TIMBER NOT ASSESSED
  • matches: LOT 9 DP 19723  LOT 12 DP 384274  LOT 8 DP 30287  LOT 9 DP 2402 

What I want to be able to do is remove the matched part from appellation on the way through leaving me with both the matches as individual features, and a subset of appellation with the matches removed. The resultant appellation in this example would be: PT RS 17343 17491 BLK VII X XI TENGAWAI SD-TIMBER NOT ASSESSED

 

I would be very grateful for any help with this.

Regards, Paul

 

I’d treat this like you want to remove every ‘found’ Lot/DP value from the original appellation string.

If the StringSearcher’s All Matches list is called ‘lots’, then this in python will remove those lots from the full appellation. 

    def input(self, feature):

appellation = feature.getAttribute('appellation')
lots_array = feature.getAttribute('lots{}.match',list)

for lot in lots_array:
appellation=appellation.replace(lot,'').lstrip()

feature.setAttribute('appellation',appellation)
self.pyoutput(feature)

 


You can do this with a StringReplacer in Regex mode, using the regular expression you provided.

 


Thank you both for your responses.

Very much appreciated!🙂


Reply