A simple question in regular expression

I'm new to regex (15 minutes of experience), so I can't figure it out. I just want something that matches an alphanumeric string without spaces in it. For instance:

"ThisIsMyName" must match, but "This is my name" must not match.

+3
source share
5 answers

^[a-zA-Z0-9]+$will match any letters and any numbers without spaces (or any punctuation) in a string. It will also require at least one alphanumeric character. A character class is used for matching . Structure:

^       #Match the beginning of the string
[       #Start of a character class
  a-z   #The range of lowercase letters
  A-Z   #The range of uppercase letters
  0-9   #The digits 0-9
]       #End of the character class
+       #Repeat the previous one or more times
$       #End of string

, "" , , parens (a ), :

^([a-zA-Z0-9]+)$

: #, MSDN .NET. . , RegexOptions.IgnoreCase, :

^([a-z0-9])+$

+4

, , : (\w+)

0

:

\S+
0

Regex: http://regexlib.com/CheatSheet.aspx

, : http://regexlib.com/RETester.aspx

However, the answers of @eldarerathis or @Nicolas Bottarini should work for you.

0
source

I just wrote a blog post about regex, maybe this is what you might find useful :) http://blogs.appframe.com/erikv/2010-09-23-Regular-Expression

0
source

Source: https://habr.com/ru/post/1769029/


All Articles