Great resource for RegEx's useful to convert from many formats to many numeric types: [^]. Try this:
private string getID = @"'\d+'";
private Regex rxGetID;
private char[] trimQuote = new[] {'\''};
private int? htmlToInt(string match)
{
rxGetID = new Regex(getID, RegexOptions.Compiled);
string result = rxGetID.Match(match).Value.Trim(trimQuote);
int intResult;
return (Int32.TryParse(result, out intResult))
? intResult
: (int?) null; // note the weird, but required, cast here
}
// test
private void Test()
{
rxGetID = new Regex(getID,RegexOptions.Compiled);
int? result = htmlToInt("* ID='45'");
if (result != null)
{
// good to go
}
else
{
// throw error ?
}
}
«A man will be imprisoned in a room with a door that's unlocked and opens inwards ... as long as it does not occur to him to pull rather than push» Wittgenstein