Regular expression lookhead lookbehind

时间:2015-06-26 09:39:11

标签: .net regex devexpress expression lookahead

I need some help with a regular expression for .NET, I have an input field for a telephone number.

I use a regex to format the value (050 33 11 00) to this format:

+32(0)50/33.11.00

But when I insert following value 09 323 23 56 I want to get following result:

+32(0)9/323.23.56

I've been looking at lookahead but can't find a working solution.

I'm using the folowing regex: (\x2B{1}3{1}2{1}\x28{1}\d{1}\x29{1}\d{2}\/\d{2}\.\d{2}\.\d{2}) which works for the first value.

The regex is placed on a textbox as editMask, so i would like instant live sanitizing.

textEdit.Mask.EditMask = editMask;

1 个答案:

答案 0 :(得分:0)

You can use the following replacement:

\b0(\d{1,2})\s+(\d{2,3})\s+(\d{2})\s+(\d{2})\b

This regex will match full "words" starting with 0, followed by 1 or 2 digits, then whitespace, 2 or 3 digits, whitespace, 2 digits and again whitespace and 2 digits.

Replace with +32(0)$1/$2.$3.$4

See demo.