cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
984
Views
0
Helpful
9
Replies

strip spaces via regex on Vcs or on Tms Phonebook

Bar1s
Level 1
Level 1

Hello Guys,

Our customer has a DC that entered phone numbers with random spaces in between numbers.

We added phone book TMS over CCM which includes those numbers. 

Result is something like that.  "12 3  45 67@example.com"  or  "1234 56 7@example.com"

So my question is how can I remove those spaces ?

 

Regards,

Baris.

 

1 Accepted Solution

Accepted Solutions

No, there is no way to match the various possibilities you might have without knowing all the patterns, and even then the number of needed regex rules that will cover them all could be too many to manage.  There is no simple one catch all regex rule, regex are based off patterns.  As Wayne said, your best solution is to correct the phone numbers in AD to remove the spaces, or make them all consistent.

View solution in original post

9 Replies 9

Patrick Sparkman
VIP Alumni
VIP Alumni

\s represents a space in regex.

If all the phone numbers are formatted exactly the same, you can create a search rule using regex that will match the phone numbers with spaces, and replace it with a version that doesn't, stripping out the spaces.

Alias: 12 3 45 67@example.com

Pattern type: Regex

Pattern string: (\d.*)\s(\d.*)\s(\d.*)\s(\d.*)@(%localdomains%)

Pattern Behavior: Replace

Replace string: \1\2\3\4@\5

In the example above it's matching 4 blocks of numbers separated by spaces and the amount of numbers in each block can be endless because it's using .* for the match.  If you want to specify exactly the amount of numbers each block is supposed to match instead of an endless amount so it's more precise, replace .* with {#} where # represents the exact amount of numbers it's supposed to match, if you only have a single number to match all you need is \d.  Example would be (\d{2})\s(\d)\s(\d{2})\s(\d{2}).

Also, %localdomains% will match any SIP domain configured on the VCS, it's simpler to use in case domains change or you want the search rule to apply to multiple domains, you can also specify the exact domain if you wish.

Hello Patrick,

But there is no constant pattern about spaces. I can't determine where it can be space in url. 

There is some person has a number 12 3  45 67@example.com while the other person has a 4567 12 3@example.com, for example.

So I need to a regex code that should strip spaces any where in url.

If it is possible ?

 

Regards,

Baris.

 

 

If you know how many spaces are used within all the phone numbers, you could us regex like I've shown above, just creating a regex for each pattern to match the different amount of spaces within the phone numbers.  However, there is no way that I know of to be able to write a single regex and it work for patterns containing different amounts of spaces from address to address.

As Patrick has said, I can't think of a way to do this with a single regex.  You'll need to write many for the different numbers of spaces in the strings you are being presented.  It's not a pretty solution, but it should work.

The better option would be to go back and correct the original source so it either gives you a consistent format, or, even better, so it does not have spaces in the phone number at all.

Edit: You may also need some rules for \s* instead of just \s to cater for the multiple space characters in some of your above examples if you're doing the first option.  Like I said, it isn't going to be pretty.

Wayne
--
Please remember to rate responses and to mark your question as answered if appropriate.

Wayne

Please remember to mark helpful responses and to set your question as answered if appropriate.

Thanks guys, 

So there is not such thing that strip all indefinite spaces in url.

It looks better option is return to source which is AD and correct to format. And fixing format is more flexible on AD. 

 

Regards,

Baris.

 

 

No, there is no way to match the various possibilities you might have without knowing all the patterns, and even then the number of needed regex rules that will cover them all could be too many to manage.  There is no simple one catch all regex rule, regex are based off patterns.  As Wayne said, your best solution is to correct the phone numbers in AD to remove the spaces, or make them all consistent.

moyo oyegunle
Level 1
Level 1

Hello

I agree with everyone, the most expedient way to do this is to just clean your data. It's always better to start with clean data than trying to work on it later.

I do though think this is possible though using CPL in a VCS. Tested it today(ver x8.5.1) and it seems to work. CPL below i just changed the CPL example that was used to replace domains.

<?xml version="1.0" encoding="UTF-8" ?>
<cpl xmlns="urn:ietf:params:xml:ns:cpl"
  xmlns:taa="http://www.tandberg.net/cpl-extensions"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="urn:ietf:params:xml:ns:cpl cpl.xsd">
  <taa:routed>
    <address-switch field="destination">
      <address regex="[%20]*(\d*)[%20]*(\d*)[%20]*(\d*)[%20]*(\d*)[%20]*(\d*)@example.com">
        <proxy>
          <failure>
            <!-- Failed to contact using example.com, retry the request with example.net -->
            <taa:location clear="yes" regex="[%20]*(\d*)[%20]*(\d*)[%20]*(\d*)[%20]*(\d*)[%20]*(\d*)@example.com" replace="\1\2\3\4\5@example.com">
              <proxy/>
            </taa:location>
          </failure>
        </proxy>
      </address>
    </address-switch>
  </taa:routed>
</cpl>

Caveat

1 This should work with SIP only( In the SIP RFC 3261 whitespace is implemented as %20)

2 I am using Patrick's idea below but changing it .You don't need to know the amount of spaces  between digits only the maximum amount of digits.So in this expression you need [%20]*(\d*) for every digit you plan to capture.

3 There is probably a smarter regex expression for this but let me know if this works for you.

This will work just like the search rule example I provided, but still the issue comes down to not knowing how many total sets of digits or spaces within the phone numbers, and I don't think he's going to want to go through all X amount of phone numbers to make sure he has enough regex rules to capture all the various versions of phone numbers.  In short, it's possible, but the overhead to make it possible and the management of it later on is too much to even attempt.  It's best to fix the phone number entries in AD and make them all the same format.

Patrick I agree totally with you the best way is to just clean the data and I stated that  in my last comment.I am more interested in this as an "intellectual can it be done" rather than for a practical benefit.

The difference between this regex and the original regex you wrote is in theory this should still work no matter the amount of spaces between the extension digits as long as the space is represented by a %20 which is why is stated the SIP caveat.(On another note thanks for mentioning this, you pointed out an error in the original regex and I believe I have corrected it below.) I am not aware of the kind of environment he has but in my experience most environments have constant length extensions and if that is the case then this is useful.

Updated Regex

<?xml version="1.0" encoding="UTF-8" ?>
<cpl xmlns="urn:ietf:params:xml:ns:cpl"
  xmlns:taa="http://www.tandberg.net/cpl-extensions"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="urn:ietf:params:xml:ns:cpl cpl.xsd">
  <taa:routed>
    <address-switch field="destination">
      <address regex="(.*)(?:%20)*(\d*)(.*)@example.com">
        <proxy>
          <failure>
            <!-- Failed to contact using example.com, retry the request with example.net -->
            <taa:location clear="yes" regex="(?:%20)*(\d*)(?:%20)*(\d*)(?:%20)*(\d*)(?:%20)*(\d*)(?:%20)*(\d*)(?:%20)*(\d*)@example.com" replace="\1\2\3\4\5\6\@example.com">
              <proxy/>
            </taa:location>
          </failure>
        </proxy>
      </address>
    </address-switch>
  </taa:routed>

I tested this and it worked for me as long as the extension was 6 digit no matter the space I left between digits.

Please test and let me know if it works or does not or if there was a test case it did not cover.

RegEx expressions are supposed to be really powerful, the VCS implementation reduces how they can be used but whitespace filtering is normal in RegeEx usage in programming languages which is why am curious as to why there is no workaround.