How to select whole text without special characters in single match? [duplicate] - c#

This question already has answers here:
How do I remove all non alphanumeric characters from a string except dash?
(13 answers)
Closed 3 years ago.
I have some text, I need to select only alphanumeric characters only in single match.
I have tried this in regex
[^\W]+
Pattern : [^\W]+
Input: This is "My Page"
https://rubular.com/r/PMQwahJIqqiOOI
Output I Need: This is My Page

Remove everything that is not word character or space using this regex,
[^\w ]+
with empty space.
Regex Demo

Related

Regex to match any character except number of digits (12) [duplicate]

This question already has answers here:
Regex: match everything but a specific pattern
(6 answers)
Match everything except for specified strings
(7 answers)
Closed last month.
I tried regex [^(\d{12})$] to exclude 12 digits in any place in the sentence but it exclude any number.
example: test1234testing123131333231l:ast
I tried regex [^(\d{12})$]
example: test1234testing123131333231l:ast
matches any character except numbers:
matches : test , testing , l:ast
not match : 1234 , 123131333231
while I need to exclude "123131333231" only, kindly provide your support

C# Regular Expression ends in _DXX where X is number [duplicate]

This question already has answers here:
How do I match an entire string with a regex?
(8 answers)
Closed 4 years ago.
I am trying to create a regular expression pattern in C# which allow you to have
next pattern: _DXX at the end of your .
Example :
04R5714A_D15 is correct
04R5714A_D05 is incorrect
04R5714A_D5 is correct
I tried : .*_D([1-9]{1}[0-9]?) but it didn't work :
.*_D[1-9]\d?$ should work for you.
Demo
.* catches everything up until your underscore
_D is a literal match
[1-9] matches one number in that range
\d? matches 0 or 1 single number (0-9)
$ is the end of the string

Regex - Minimum 6 chars and no whitespace. Everything else allowed [duplicate]

This question already has answers here:
Regular expression for not allowing spaces in the input field
(5 answers)
Closed 3 years ago.
I'm trying to use regex which checks only two things
Minimum 10 characters (No Max)
No whitespace allowed
I'm able to check minimum 10 chars with #"^[a-zA-Z0-9]{10,}$" and disallow white space with ^[^0-9 ]+$
Now the problem is, how to combine both of these and allow everything(alphanumeric including special characters) except white space
You could try to use a simpler regex pattern just to accept anything that is not a white-space: ^\S{10,}$
\S - matches any non-white-space character. More details here: https://learn.microsoft.com/en-us/dotnet/standard/base-types/regular-expression-language-quick-reference

How to include '-' in the string with regex check [duplicate]

This question already has an answer here:
How to add hyphen to regex
(1 answer)
Closed 4 years ago.
I have the below regex, which currently allows '_' but not '-'.
string validCharacters = #"^\w+$";
Regex.Match(componentName, validCharacters);
But I want to also to include '-' as a valid character. The '-' can be at any place in the string. i,e: first,last,middle,after '_' etc.
Below are the few test cases:
"DTD_rtop-234"
"DTD-rtop_234"
"-DTD_rtop-234"
"DTD_rtop-234-"
"DTD_-rtop-234"
Any help will be much appreciated.
Combine the - character with the \w characters in a single character class:
[-\w].
Your desired regex is therefore:
^[-\w]+$.

Regular expression for characters after '.' [duplicate]

This question already has answers here:
How do I match an entire string with a regex?
(8 answers)
Closed 6 years ago.
I need to detect following format when I enter serial number like
CK123456.789
I used Regex with pattern of
^(CV[0-9]{6}\.[0-9]{3}
to match but if I enter
CK123456.7890
it still able to proceed without flagging error. Is there a better regular expression to detect the trailing 3 digits after '.'?
Depending on how you use the regular expression matcher, you might need to enclose it in ^...$ which forces the pattern to be the whole string, i.e.
^CK[0-9]{6}\.[0-9]{3}$ (Note the CK prefix).
I've also removed your leading (mismatched) parenthesis.

Categories

Resources