Skip to main content
Question

StringReplacer to replace all text?


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 

 

3 replies

geomancer
Evangelist
Forum|alt.badge.img+47
  • Evangelist
  • May 31, 2023

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.

 


geomancer
Evangelist
Forum|alt.badge.img+47
  • Evangelist
  • May 31, 2023

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

Conditional_Value_2


ebygomm
Influencer
Forum|alt.badge.img+32
  • Influencer
  • May 31, 2023

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


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