Question

search regex with python caller

  • 9 October 2019
  • 5 replies
  • 1 view

Badge

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

Userlevel 2
Badge +17

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

Badge

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:

Badge

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:

Badge

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?

 

Userlevel 1
Badge +21

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)

Reply