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:]]
Related
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.
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.
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 .
I'm looking for a regex that will allow Alpha Numeric and most all special characters except white space. It should be usable in c#. It would be nice if .net supported posix style but I can't seem to get it to work. TIA
Pretty sure \S (note capitalization) is the non-whitespace character class.
Something along the lines of: [^\s]+ should do the trick.
This roughly translates as "match one or more consecutive characters that are not whitespace" (\s matches a space, tab, or line break).
I have a regular expression
^[a-zA-Z+#-.0-9]{1,5}$
which validates that the word contains alpha-numeric characters and few special characters and length should not be more than 5 characters.
How do I make this regular expression to accept a maximum of five words matching the above regular expression.
^[a-zA-Z+#\-.0-9]{1,5}(\s[a-zA-Z+#\-.0-9]{1,5}){0,4}$
Also, you could use for example [ ] instead of \s if you just want to accept space, not tab and newline. And you could write [ ]+ (or \s+) for any number of spaces (or whitespaces), not just one.
Edit: Removed the invalid solution and fixed the bug mentioned by unicornaddict.
I believe this may be what you're looking for. It forces at least one word of your desired pattern, then zero to four of the same, each preceded by one or more white-space characters:
^XX(\s+XX){0,4}$
where XX is your actual one-word regex.
It's separated into two distinct sections so that you're not required to have white-space at the end of the string. If you want to allow for such white-space, simply add \s* at that point. For example, allowing white-space both at start and end would be:
^\s*XX(\s+XX){0,4}\s*$
You regex has a small bug. It matches letters, digits, +, #, period but not hyphen and also all char between # and period. This is because hyphen in a char class when surrounded on both sides acts as a range meta char. To avoid this you'll have to escape the hyphen:
^[a-zA-Z+#\-.0-9]{1,5}$
Or put it at the beg/end of the char class, so that its treated literally:
^[-a-zA-Z+#-.0-9]{1,5}$
^[a-zA-Z+#.0-9-]{1,5}$
Now to match a max of 5 such words you can use:
^(?:[a-zA-Z+#\-.0-9]{1,5}\s+){1,5}$
EDIT: This solution has a severe limitation of matching only those input that end in white space!!! To overcome this limitation you can see the ans by Jakob.