-1

I wanted to count a number of character or special case symbols or number in a given sentence and limit a sentence to only 25 .So I have used this regex ^[^a-zA-Z0-9 ]*{1,25}$ .But this regular expression considers and counts the space/white space.

For example : "this is the sentence i am count" Now here we have 25 characters.But above regular expression will count space/white space in btw words and reports below sentence as 25 characters

"this is the sentence i am"

Can you any one help me on this query ?

Thanks in advance

1 Answers1

-1

possible duplicate of Regex match count of characters that are separated by non-matching characters

But you can try like this: If you want exactly 25 characters in your string

^((?:\s*\w){25})$

or if you want 1 to 25 characters in your string try this:

^((?:\s*\w){1,25})$
Community
  • 1
  • 1
anusha
  • 2,087
  • 19
  • 31