INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Expression Help: Replace  (Read 1038 times)

locust

  • Citizen of the Universe
  • *****
  • Posts: 699
Expression Help: Replace
« on: January 13, 2012, 11:06:11 pm »

I am looking the use the name field and use the Replace expression to remove all possible special characters and numbers from the name field including " " You should be able to copy and paste it, but to type it press Alt+0160.. (I'm not sure what it is but it isn't a space) and replace them with ; So I can then generate a list of all words.

Anyway I got somewhat confused with loads of replace expressions needed, is there an easier way to do this? Maybe with regex?

Thanks
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Expression Help: Replace
« Reply #1 on: January 13, 2012, 11:28:11 pm »

There are probably too many possible special characters to use Replace in a single expression to be useful.

Regex() can be used with limitations - if you have Names with less than 9 sequences of Chars To Accept/Chars to Replace, this is pretty straightforward, but not optimal really.  The 9 span limit can be extended, but is clumsy.

This problem really calls for RegexReplace() though, which is not available.  This would allow you to globally replace any characters you designate with whatever you want, once or globally.
Logged
The opinions I express represent my own folly.

locust

  • Citizen of the Universe
  • *****
  • Posts: 699
Re: Expression Help: Replace
« Reply #2 on: January 13, 2012, 11:38:27 pm »

Could I do it in 4 stages? I've counted the amount of characters I wish to replace with ; and it totals 33

So if there is a limit or 9 sequences (Do you mean the amount of times I can use replace?)

Could I have 3 custom fields [name Calc 1], [Name Calc 2] & [Name Calc 3]

[Name Calc 1] one would call upon [Name] and replace 9 chars..

Then [Name Calc 2] could call upon [Name Calc 1] with the replace function and so on.

And then the last 6 characters needing replaced could just be the expression in the view calling upon [Name Calc 3]

Would this be a way to do it?
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Expression Help: Replace
« Reply #3 on: January 14, 2012, 02:05:10 am »

Replace() only allows replacement of a single sequence of one or more characters, so to replace 33 different characters, you'd need 33 nested Replace() functions, each one operating on the resulting value from an inner call.  So it won't matter how many stages you use; it will still require 33 Replace() calls.

The 9 capture limit I mentioned above is an MC implementation limit in Regex(), and does not affect Replace().  I mentioned the 9 capture limit of Regex() because the problem you're trying to solve isn't solvable generally using Regex(), but can be solved specifically for cases where there are less than 9 sequences of "<Acceptable Chars><Non-acceptable Chars>".  You can think of any Name as a repeating pattern of Acceptable Chars followed immediately by Non-acceptable Chars, again, and again, and again.  This could be repeated many times.  When the number of repetitions is less than 9, we can formulate an RE that can describe and solve this.  So if you're sure you'll have less than 9, we can use Regex().

As I mentioned above, this class of problem is better solved with a global replacement function, because it becomes trivial to do.  For example, it could be as simple as:

   RegexReplace([Name], /#[^a-z0-9]#/, ;, GLOBAL)

which globally replaces all characters NOT a through z or 0 through 9, with a semicolon.
Logged
The opinions I express represent my own folly.

locust

  • Citizen of the Universe
  • *****
  • Posts: 699
Re: Expression Help: Replace
« Reply #4 on: January 14, 2012, 02:53:06 am »

Thanks for the clarification, I guess it is the long way then..

Thanks MrC
Logged
Pages: [1]   Go Up