开发者

Regular expression substitution for ENUM record

How do I susbtitute in matched groups from 1 regular expression into another regular expression in C#?

I need to process an ENUM DNS record where the first half of the record is a regular expression to apply to the lookup value and the second half is a regular expression that uses the matches from the first.

Example of an ENUM record for a lookup on +18001234567

!^\+1800(.*)$!sip:1641641800\1@tollfree.sip-happens.com!

The separate regular expressions are delimited by the ! character and are:

^\+1800(.*)$
sip:1641641800\1@tollfree.sip-happens.com

The correct result of applying the two expressions is:

sip:16416418001234567@tollfree.sip-happens.com

I can do it be iterating through the matches and using a crude string search and replace but I'm hoping there is a better way. I'm pretty sure in Perl and other languages I could do somehting like:

"+18001234567" =~ s/^\+1800(.*)$/开发者_StackOverflowsip:1641641800\1@tollfree.sip-happens.com/


I ended up doing a crude string substitution replace \n with ${n}.

Regex.Replace(enumSubstitution, @"\\(?<digit>\d)", @"${${digit}}");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜