开发者

What does this regular expression do?

开发者 https://www.devze.com 2023-04-03 06:43 出处:网络
Can someone pleas开发者_JAVA技巧e summarise what this regular expression will do? ValidationExpression=\"^[a-zA-Z0-9\'.\\s\\-&\\(\\)]*$\"

Can someone pleas开发者_JAVA技巧e summarise what this regular expression will do?

ValidationExpression="^[a-zA-Z0-9'.\s\-&\(\)]*$"

Is there any online tools that can summarise this?


The Regular Exprression Analyzer outputs this:

Parse Result:  Success!
- Sequence: match all of the followings in order
    -  BeginOfLine
    -  Repeat
          - AnyCharIn[ a to z A to Z 0 to 9 ' . WhiteSpaceCharacter - & ( )]
          - zero or more times
- EndOfLine


To answer the -

Is there any online tools that can summarise this?

Try - http://gskinner.com/RegExr/

You can type in a RegEx then hover over the relevant bits and it will explain what is going on.


^ and $ are anchors that anchor the epxression to the start and the end of the string.

[a-zA-Z0-9'.\s\-&\(\)] is a character class that allows any of the characters inside the []

a-z is a character range (- is the range operator here), meaning all characters from a to z.

\s is a whitespace character (space, tab, newline)

\( is a literal (, \ is for escaping

* is a quantifier that allows 0 or more characters inside the character class.

That means your regex can match an empty string or a string consisting only of characters from inside your character class.


There's an error in it, I'd say. The period, which matches any character, should probably be escaped to match only the character .... Otherwise, it will match any line.

Assuming that the period is escaped, it will match a line containing only letters, numbers, 's, .s, whitespace, -s, &s and parenthesis, but any number or combination of these.


This regex is for exact match if there is any content in the string, or it will match if the string is empty. ^ means match from start and $ match till end of string. they are called anchors

this [] is called character class, every thing inside is allowable in string.

by the way above regex can be more simplified as (?i)^[a-z0-9'.\s\-&\(\)]$. (?i) is ignore case flag for in-case sensitive match

0

精彩评论

暂无评论...
验证码 换一张
取 消