Skip to main content
Hi There,

 

 

I'm attempting to cut out bits and pieces out of an attribute value in a shape file, and write different parts to different newly created attribute fields. I’ve sort of played around with StringSearcher, but my knowledge of Regular Expressions are very limited.

 

Here's an example of what my attribute field looks like:

 

 

NAME

 

Tarkleigh Hill 1256 Feet (0,82)

 

King's Prime Tower 953 Feet (0,11)

 

The House of Song 1587 Feet (0,16)

 

 

What I want as an output is (the two new field that need to be generated):

 

 

NAME1                                 HEIGHT

 

Tarkleigh Hill                        1256

 

King's Prime Tower             953

 

The House of Song             1587

 

 

So essentially, the "Feet" (Which is a constant that will always be the same), and the brackets, including whatever is contained within them are both thrown away and irrelevant to me. I just want to have the actual name in one field, and the foot value in another.

 

 

Any idea on what kind of Regular Expression would get me there, or any other method for that matter?

 

 

 

Thanks!
Hi,

 

 

the following regexp will give you two result groups, one containing all the characters up to the first space followd by one or more digits, and another group containing the following digits:

 

 

(.*) (\\d+)

 

 

Example using a StringSearcher:

 

Input = 'King's Prime Tower 953 Feet (0,11)'

 

 

Gives:

 

_matched_parts{0} = 'King's Prime Tower'

 

_matched_parts{1} = '953'

 

 

Then use an AttributeRenamer as appropritate.

 

 

David
Thanks a million David, worked perfectly.
I think " containing all the characters up to the first space followd by one or more digits" is semanticaly incorrect.

 

"at least 1 digit wich is directly after exactly 1 space wich is after 0 or more wordcharacters" i would say.

 

 

;

 

 

Reply