RegEx for text field with max length 140 with white Space - asp.net

I have Problem with my RegEx it allow me to enter any text but when I have white space it throw error.what I have text field to enter summary and the summary is lenght is 140 with white space my RegEx [\w\n\r]{0,140}

Try this [\w\n\r\t ]{0,140}
That includes tabs and spaces as well.

Or, more succinctly, [.\n]{0, 140}. The . operator will match any character except new lines (\n), hence the grouping.
If you're using .Net to do the RegEx matching, then you don't need \n when called like this:
Match m = Regex.Match("some string", #".{1, 140}", RegexOptions.SinglelLine);
HTH.

Related

How to remove characters between space and specific character in R

I have a question similar to this one but instead of having two specific characters to look between, I want to get the text between a space and a specific character. In my example, I have this string:
myString <- "This is my string I scraped from the web. I want to remove all instances of a picture. picture-file.jpg. The text continues here. picture-file2.jpg"
but if I were to do something like this: str_remove_all(myString, " .*jpg) I end up with
[1] "This"
I know that what's happening is R is finding the first instance of a space and removing everything between that space and ".jpg" but I want it to be the first space immediately before ".jpg". My final result I hope for looks like this:
[1] "This is my string I scraped from the web. I want to remove all instances of a picture. the text continues here.
NOTE: I know that a solution may arise which does what I want, but ends up putting two periods next to each other. I do not mind a solution like that because later in my analysis I am removing punctuation.
You can use
str_remove_all(myString, "\\S*\\.jpg")
Or, if you also want to remove optional whitespace before the "word":
str_remove_all(myString, "\\s*\\S*\\.jpg")
Details:
\s* - zero or more whitespaces
\S* - zero or more non-whitespaces
\.jpg - .jpg substring.
To make it case insensitive, add (?i) at the pattern part: "(?i)\\s*\\S*\\.jpg".
If you need to make sure there is no word char after jpg, add a word boundary: "(?i)\\s*\\S*\\.jpg\\b"

Regex - White Space

I have a string coming out as:
<span class="abc"> test </span> styletext
I want to grab just the styletext part which is dynamic and give it some css styles.
Can I use regex to select the whole part after the white space and apply the style? How do I target the part after the white space?
Try this as a regex:
^/span\s*(.*)
You may need to escape the "\" depending on the language you are using.
The text captured in the group will be the style text.
It "translates" as: starting at the beginning of the string (^) match the text "/span", followed by any number of whitespace characters (\s*), followed by any number of any type of character (.*). The parenthesis tells it to capture the last part for later use.

How do I write a regular expression that matches text that does not contain all caps?

I'm using the ASP.NET RegularExpressionValidator
I need a regular expression to keep users who fill out a form from using all caps.
For example, if they write their name:
Bob JONES or BOB JONES or BOB JOnes or whatever, it will not match.
I am able to match all caps with this regular expression:
[A-Z]{2,10}
But the RegularExpressionValidator requires me to match valid text, not invalid text.
If your goal is to have each word have no more than 1 capital letter in a row at a time, and assuming it's okay to restrict to ASCII letters, try something like this:
^(?:[a-z]|[A-Z](?![A-Z])|['-])+$
In other words, the string must be entirely composed of either lowercase letters, or uppercase letters not followed by another uppercase letter.
This works for single words. For multiple words (like a full name, first and last), simply add a space to the alternation:
^(?:[a-z]|[A-Z](?![A-Z])|[\s'-])+$
(Edited to allow apostrophe and hyphen punctuation)
use this Regex: #"^[^A-Z]*$" It will match anything that not contains upper case characters.
use this regular expression ^[a-z ]+$
if you want catch names like Bob Jones use this one ^([A-Z][a-z ]+)+$
Maybe i'm just stating the obvious, but couldn't you just to myVar.string.toLower before doing the Compare?

Text box validation using regular expression in asp.net

I have a textbox and have to use the regular expressions in asp.net
My text should not allow the spaces in first and last place.
Output should be:
Valid:
[India Bangalore]
Not valid:
[ India Bangalore ]
i.e : user can enter the spaces in between the words but not in first position and last position.
If you have solution in JavaScript that is also fine.
Trim() should remove any trailing or leading spaces.
Try this please :
^[^\s].*[^\s]$
It simply match input which:
not to start with any white space ^[^\s] followed by any character even white spaces .* and not end with any white space [^\s]$.
Any way calling Trim() method on input string in server-side is much easy .

regular expression for no blank space b/w text

Please tell me how to check regular expression for no blank space b/w text.
If you mean "What's the reqular expression to check there is no white space in a string", the following pattern will work:
^[\S]*$
This will find any string that only contains non-white space (spaces, new lines, tabs, etc).
I don't know if it is the regular expression you are looking for but, [:space:] will match any whitespace character, while [:blank:] will match space and tab characters only.
Both are used inside square brackets, e.g. [[:space:]]

Resources