Regex question

Keith Crotty 81 Reputation points
2019-12-26T15:01:09.993+00:00

I am using Regex in a C# program. What I really want is an expression that will check for valid data input, letters, numbers, punctuation, space, etc. But, I am having problems getting even a simple alpha-num to work.

I defined 2 strings
const string C_RegXNumbers =
@"(?<=^| )\d+(.\d+)?(?=$| )|(?<=^| ).\d+(?=$| )"; //this works

const string C_RegXAlphaNumPlus = @"^[a-zA-Z]*$"; //this doesn't

Then in the code executing the Regex

I put QnA in the tag. I had to put something, but it would not let me put in C# or Regex. Something seems not right there.

if (Regex.IsMatch(strThisData, C_RegXNumbers)) …

if (Regex.IsMatch(strThisData, C_RegXAlphaNumPlus)) ...

The first one works
The much simpler fails no matter what I have tried (took out the digits)

The input string is "Open Screen". Originally, it had an exclamation point after, but I'm just trying to figure out what I'm doing wrong, so keeping it simple.

I have cut and pasted a bunch of examples, but they all fail.

And.. does anyone have a string to, basically, accept valid keyboard text. No weird printing chars, etc. I cant find one that works in my searches. Nums, AlphaNum, /?,.:;[]{} etc.

I put QnA into the Tag field. There is no dropdown and you can not put in C# Regex. Something not working properly?

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
35,970 questions
0 comments No comments
{count} votes

1 additional answer

Sort by: Most helpful
  1. Dave Patrick 426.1K Reputation points MVP
    2019-12-26T15:07:07.347+00:00

    QnA currently only supports the products listed in right-hand pane. Better to reach out to subject matter experts in dedicated forums over here.

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=netfxbcl

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=csharpgeneral

    0 comments No comments