Take the 2-minute tour ×

I have this code down here and I need to return the args.Content (my input data) with only digits and deleteing the rest of characteres. I've been trying many things with regular expressions but it didnt work for me. I have almost no idea of C# and I really need the help from the programers of this website.

using System;
using VisualWebRipper.Internal.SimpleHtmlParser;
using VisualWebRipper;
public class Script

    public static string TransformContent(WrContentTransformationArguments args)
            //Place your transformation code here.
            //This example just returns the input data
            return args.Content;
        catch(Exception exp)
            //Place error handling here
            args.WriteDebug("Custom script error: " + exp.Message);
            return "Custom script error";

Hope you can help

share|improve this question

3 Answers 3

up vote 3 down vote accepted

Just delete anything that is not a digit. There is a predefined character class for digits: \d, the negation is \D.

So you regex is simply:


In your C# code it would be something like

return Regex.Replace(args.Content, @"\D+", "");
share|improve this answer
Oh great, many thanks...now I need to separate this number between ";" every 8 numbers. The args.content now returns to me 16 digits like this "0123456789012345" and I need to get something like this : "01234567;89012345" So many thanks again ^^ –  TheDeadPixel May 25 '12 at 9:11
Is the ; in the original string or do you want to insert it afterwards? –  stema May 25 '12 at 9:22
Just instert it, but I've already done it. Thanks anyways ^^ –  TheDeadPixel May 25 '12 at 12:23

Certainly not the most efficient, but oh, well, I couldn't resist doing some LINQ:

var digitsOnly = new string(args.Content.Where(c => char.IsDigit(c)).ToArray())
share|improve this answer
+1: I now shall delete my own identical answer. This isn't a job for Regex IMHO –  Binary Worrier May 25 '12 at 7:54
StringBuilder builder = new StringBuilder();
Regex regex = new Regex(@"\d{1}");
MatchCollection matches = regex.Matches(args.Content);
foreach (var match in matches)
return builder.ToString();
share|improve this answer

Your Answer


