Skip to main content

I am wanting my StringReplacer to search for values which start with a certain string, and replace the ENTIRE value with a new string (not just the start).

 

I have table with a list of values starting with "Sh 1" and "Sh 77", and they all have following text after Sh 1 and Sh 77. I would like to replace the entire value, e.g. "Sh 1 Rs 401 Rakaia to Chertsey" should be replaced with "State Highway 1".

 

I have tried a few expressions, but currently I am only able to replace the "Sh 1" part of the string, not the following text.

 

How do I change my expression so the entire value is replaced?

 

image 

 

You are close, use one of these to match the whole text starting with "Sh 1 ":

^Sh 1 .+
^Sh 1 .*

" .+" means one or more characters, ".*" means zero or more characters.

 


Creating regular expressions is fun, but it is probably much easier to use Conditional Values in an AttributeManager.

Conditional_Value_2


If you want to replace Sh 1 with State Highway 1 and Sh 77 with State Highway 77, you could do this

image

(Sh\s)(\d+).*

So match Sh followed by a space and replace with State Highway, match the numbers after and put that group (\2) back in the replacement text


Reply