Skip to main content
Solved

Update a list element base on another list element


pauld
Contributor
Forum|alt.badge.img+1

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

 

Best answer by geomancer

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

 

View original
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

ctredinnick
Supporter
Forum|alt.badge.img+21

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)

 


geomancer
Evangelist
Forum|alt.badge.img+69
  • Evangelist
  • Best Answer
  • April 17, 2024

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

 


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

Thank you both for your responses.

Very much appreciated!🙂