cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Announcements
887
Views
5
Helpful
2
Replies
gavin han
Beginner

help in regards to regex for vsc

Hi,

I need some help with regex.

1) any pattern that starts with 15 and if it is 12 to 15 digit long (including 1st digits 15) than consider it as a good match and then send the call to destination zone

2) any pattern that meets requirements in (1) but if it has "@domain.com" than take out "@domain.com" from the pattern and send that 12 to 15 digit pattern to destination zone.

3) any incoming call that is valid URL or DN i.e. if url is sip:2xxxyyyy@domain.com or h323:xxxyyyzzzz than consider it as a valid URI or DN and send it to the destination zone.

what would be regex to accomplish requirements in 1,2,3.

I'm kinda new to regex. is there a good tutorial for regex with examples.

Thanks all for your help.

2 REPLIES 2
gubadman
Participant

you can do 1 and 2 with something along the lines of:
regex: (15\d{10,13})(@domain\.com)?
replacement: \1

this is 15 follow by min10, max 13 more digits with optional domain.com (the . between domain and com is escaped as . is a special character in regular expressions)
then the replacement is just the first capture group and not the second capture group so if there is a domain.com it's removed.

This is a good reference - http://www.regular-expressions.info/reference.html

awinter2
Rising star

Gavin,

there are many great regex references online, one of them being http://www.cheatography.com/davechild/cheat-sheets/regular-expressions/.

The 'Check pattern' tool (Maintenace > Tools > Check pattern) on the VCS itself is also a great tool for validating regular expressions for making sure that regex expressions work the way you intended them to.

Now regarding the specific patterns you requested, I'll give it a go (These come without warranty ):

1)

Pattern string: 15\d{10,13}

Pattern behavior: Leave

2)

Pattern string: (15\d{10,13})(@domain\.com)?

Pattern behavior: Replace

Replace string: \1

3) The following regex would match a called alias which is either a URI (something@domain.tld) or a DN entirely consisting of digits. Please note that the '.' regex matches any character except newline:

((.+@.+\..+)|(\d+))

The above regex is not very strict in terms of the URL part, it will match

1 or more characters followed by an @-symbol followed by 1 or more characters followed by a punctuation followed by 1 or more characters.

Hope this helps you on the way

- Andreas

Create
Recognize Your Peers
Content for Community-Ad