Java: Regex To Check If Content Contains All Letters Or Not
Posted by tech on
September 10, 2009
|
|
Here is a method using the Java programming language that checks via regex if the String content contains all letters or not. The letters in the String content, either uppercase and/or lowercase will be accepted. The value returned is a boolean.
1 2 3 4 | public static boolean isLetters(String content) { Pattern p = Pattern.compile("^[a-zA-Z]+$"); return p.matcher(content).matches(); } |
tags: letters, regex
No Comments
Regex To Get All Contents Within Curly Brackets
Posted by tech on
July 7, 2009
|
|
Let us say your string contains this data
1 | {"1":"one", "2":"two"},{"3":"three", "4":"four"},{"5":"five", "6":"six"} |
While regex can slow down performance, I decided to use it for this situation because I can do it using only a regex pattern. This regex will get all instances of a substring between two curly brackets { and }. In the example above, the result should be 3 entries since there are 3 sets of curly brackets. Please see the regular expression below.
1 | \\{[^}]*\\} |
tags: curly bracket, regex
No Comments
A Good Regex For Creating Usernames
Posted by tech on
November 3, 2008
|
|
A regular expression (called regex) is a way for a programmer to instruct how a program should look for a specified pattern in text and then what it should do when each pattern match is found. Rather than going through each character of a string and doing matches, regex makes life easier for programmers to do search and matches. This sample regex is a good pattern for use in creating usernames.
The regex below means that only alphanumeric (only lowercase letters) are allowed including an underscore and a dot.
1 | ^[a-z0-9_.]$ |









