Skip to main content
Question

search regex with python caller


Forum|alt.badge.img

Hello,

I want to find a regex with python caller.  

The text_line is like Híd neve: Líra utca -  gyalogos híd. And I want to get only: Líra utca -  gyalogos híd

I was able to do it with StringSearcher, where the expression for the regex was like : (?<=Híd neve: )\w.* 

Now I am tring it within python, but it doesn't give back value (it should be like: Líra utca - Ördög-árok feletti gyalogos híd)

Could you help me, where is the mistake?

class FeatureProcessor(object):
    def __init__(self):
        self.comp_re = re.compile("(?<=Híd neve: )\w.*")
        #pass
    def input(self,feature):
        text_line = feature.getAttribute('text_line_data')
        matches = self.comp_re.findall(text_line)
        if matches:
            feature.setAttribute('PyTrackExtents', matches[0])
        self.pyoutput(feature)

5 replies

takashi
Influencer
  • October 9, 2019

I was able to get your desired result from the script you posted.

Perhaps you just need to expose the new attribute name "PyTrackExtents'. See @egomm's answer to this question.

How to write an attribute into a new attribute with Pythoncaller


Forum|alt.badge.img
  • Author
  • October 9, 2019
takashi wrote:

I was able to get your desired result from the script you posted.

Perhaps you just need to expose the new attribute name "PyTrackExtents'. See @egomm's answer to this question.

How to write an attribute into a new attribute with Pythoncaller

for me it is like this:


Forum|alt.badge.img
  • Author
  • October 9, 2019
takashi wrote:

I was able to get your desired result from the script you posted.

Perhaps you just need to expose the new attribute name "PyTrackExtents'. See @egomm's answer to this question.

How to write an attribute into a new attribute with Pythoncaller

For me it is like:


Forum|alt.badge.img
  • Author
  • October 9, 2019

It looks, the python script doesn't work with accentuated letters, because when I am looking for only the 'H', it gives back values.

Can you suggest mes some advice to modify the script to work also with accetuated letters?

 


ebygomm
Influencer
Forum|alt.badge.img+39
  • Influencer
  • October 9, 2019
gylona wrote:

It looks, the python script doesn't work with accentuated letters,  because when I am looking for only the 'H', it gives back values. 

Can you suggest mes some advice to modify the script to work also with accetuated letters?

 

It's probably an issue with the encoding

Try altering the first part of the python

    def __init__(self):
        self.comp_re = re.compile(ur"(?<=Híd neve: )\w.*")

What version of python are you running, this may also make a difference? Your original code works for me with 3.5+ but requires the above change to work with 2.7 (deprecated)


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