Need a regular expression to allow only one character in a text box in asp.net - expression

I need a a regular expression to allow only one character for a textbox. Actually i want to validate a text filed to enter a single charecter for Initial (for name)

In a regular expression, '.' (dot) matches a single character.
If you want to be sure that this single character is alphabetic, use:
[a-zA-Z]
or in a posix system: [:alpha:]
Now, to know exactly how to implement it, we need to know in which language your code is written.
For a starter, have a look to
http://en.wikipedia.org/wiki/Regular_expression

You can set the textbox property MaxLength to 1 and use a regex to validade if a letter.

Related

Disable #imageLiteral(resourceName: <..>) preview in Xcode?

I found image literals to be rather distracting than useful.
Is there any way to disable this Xcode feature?
A good method for this is to replace all occurrences of #imageLiteral with UIImage(imageLiteralResourceName:) initializers (thanks for the suggestion, #D6mi!). Here's how you can do it automatically:
Navigate to Find/Find and Replace... (or press ⌥⌘F).
Open the dropdown list on the right side and select Regular Expression.
For the search term, enter the following regex:
#imageLiteral\(resourceName: (.*)\)
For the replacement, enter this:
UIImage(imageLiteralResourceName: $1)
This regular expression captures the value of the resource name with (.*) and inserts it again with $1. The backslashes are for escaping the parentheses, since they count as special characters.
Note that you don't have to use regular expression in this case (as LinusGeffarth pointed out), but it can be more useful in more complex cases than this.

Regex that considers apostrophes as word characters? [duplicate]

So I want to split a string in java on any non-alphanumeric characters.
Currently I have been doing it like this
words= Str.split("\\W+");
However I want to keep apostrophes("'") in there. Is there any regular expression to preserve apostrophes but kick the rest of the junk? Thanks.
words = Str.split("[^\\w']+");
Just add it to the character class. \W is equivalent to [^\w], which you can then add ' to.
Do note, however, that \w also actually includes underscores. If you want to split on underscores as well, you should be using [^a-zA-Z0-9'] instead.
For basic English characters, use
words = Str.split("[^a-zA-Z0-9']+");
If you want to include English words with special characters (such as fiancé) or for languages that use non-English characters, go with
words = Str.split("[^\\p{L}0-9']+");

Regex for capital letters not matching accented characters

I am new to ruby and I'm trying to work with regex.
I have a text which looks something like:
HEADING
Some text which is always non capitalized. Headings are always capitalized, followed by a space or nothing more.
YOU CAN HAVE MULTIPLE WORDS IN HEADING
I'm using this regular expression to choose all headings:
^[A-Z]{2,}\s?([A-Z]{2,}\s?)*$
However, it matches all headings which does not contain chars as Č, Š, Ž(slovenian characters).
So I'm guessing [A-Z] only matches ASCII characters? How could I get utf8?
You are right in that when you define the ASCII range A-Z, the match is made literally only for those characters. This is to do with the history of characters on computers, more and more characters have been added over time, and they are not always structured in an encoding in ways that are easy to use.
You could make a larger character class that matches the slovenian characters you need, by listing them.
But there is a shortcut. Someone else has already added necessary data to the Unicode data so that you can write shorter matches for "all uppercase characters": /[[:upper:]]/. See http://ruby-doc.org//core-2.1.4/Regexp.html for more.
Altering your regular expression with just this adjustment:
^[[:upper:]]{2,}\s?([[:upper:]]{2,}\s?)*$
You may need to adjust it further, for instance it would not match the heading "I AM A HEADING" due to the match insisting each word is at least two letters long.
Without seeing all your examples, I would probably simplify the group matching and just allow spaces anywhere:
^[[:upper:]\s]+$
You can use unicode upper case letter:
\p{Lu}
Your regex:
\b\p{Lu}{2,}(?:\s*\p{Lu}{2,})\b
RegEx Demo

In Regular Expression how to add Special Character's

I have regular expression like this:
regularExp = "^[-]{0,1}([0-9]|[a-z]|[A-Z]|[\s]){0," & decNum & "}\.$"
Here I need to add all Special Character's, like ~!##$%^&*()_+{}|:"<>?[]\;',./ in VB6.0
I guess you are looking for something like POSIX bracket extensions and a special character class which matches all punctuation characters without listing them explicitly.
Unfortunately you are out of luck, since the Regular Expressions available in Visual Basic 6 are provided by the same VBScript RegExp engine which was available in IE 5.5. That engine was not updated in 15 years, so many features are missing.
Having said that, your only option is to "handpick" each and every character you want to match and put them in a character class, like this
[~!##$%^&*()_+{}|:"<>?[\]\\;',./]
Fortunately you don't have to escape all special characters within character classes, only the ones which confuse the parser. (Namely \, ^, - and ])
you can use
^[a-zA-Z._^%$#!~#,-] as referance and add more special characters which you want to allow.
You can use add special characters as below
[^%$#!~#()*\s]

WinPhone7 pass values with special character between pages

I am going to pass string value between pages.
The value contains "&" character.
Since the values are split using "&", so the value is chopped.
How can I escape this special character?
use URL encoding...
for ex: if you want '&' .. use '& amp;' (no spaces)
Recommended way is to use
Uri.EscapeUriString(stringToEscape)
method which does this for you.
Documentation at
http://msdn.microsoft.com/en-us/library/system.uri.escapeuristring%28v=VS.95%29.aspx

Resources