Re: Format string using regular expressions



On Aug 3, 6:54 pm, "Alexander Vasilevsky" <m...@xxxxxxxxx> wrote:
There is a phone number in a string such as "3223223" to format it as a
"322-32-23", using regular expressions. Is it possible?

Regular expressions are used to parse strings, not to format them. Can
you clarify why you think you need them here?

In the specific case that you give, what's wrong with this:

var result = string.Format("{0}-{1}-{2}", input.Substring(0, 3),
input.Substring(3, 2), input.Substring(5, 2));
.



Relevant Pages

  • Re: "and me" vs. "and I"
    ... Can anyone clarify for me please? ... Statements not using this format are ungrammatical, and unfortunately, ... practice. ...
    (alt.usage.english)
  • Re: Get regular expression
    ... I am inquiring with our DBAs to find out what XML features are ... usable format for these ICD9 Index entries I can propose something to ... If you were to use Regular Expressions, you would incur about the same ... Expression compares a string character-by character, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: C# programmer wants to learn assembly?? plz help
    ... address in a string has the format something@xxxxxxxxxxx? ... that regular expressions was a proper way to perform actual RFC- ... // if using / as area code separator, ...
    (alt.lang.asm)
  • Re: Another MicroLie
    ... 1.Ad-Ware and/or SpyBot?? ... 4.DVR-MS format ... 5.To clarify the link for CWShredder Update ...
    (microsoft.public.windowsxp.general)
  • Re: Validating dates with regular expressions in a German Windows PC
    ... I have an international vbs application and I am using regular expressions ... PC has the German version of windows. ... : Dim response ' response ... However, to use it with your dd.mm.yyyy format, you'd change it to: ...
    (microsoft.public.scripting.vbscript)