Results 1 to 6 of 6
Thread: How to use Regex?
- 04-28-2011, 03:49 PM #1
Member
- Join Date
- Apr 2011
- Posts
- 11
- Rep Power
- 0
How to use Regex?
I've seen on a Java tutorial website how to use regex but it always returns false even when it is true.
I've done a simplified version of my code to make it easier to assist me.
Java Code:import javax.swing.JOptionPane; public class test { static String text = "sdijv"; public static void main (String[] args) { JOptionPane.showMessageDialog(null, "" + text.matches("^[a-z]$")); } }Newb today, Pro tomorrow,
Soulmed
- 04-28-2011, 03:55 PM #2
What do you think that regular expression is "saying"? Why do you think that should match?
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 04-28-2011, 04:07 PM #3
Member
- Join Date
- Apr 2011
- Posts
- 11
- Rep Power
- 0
to my understanding, that regex should validate that all characters in the string are letters between a to z and nothing else.
Newb today, Pro tomorrow,
Soulmed
- 04-28-2011, 04:13 PM #4
Member
- Join Date
- Apr 2011
- Posts
- 11
- Rep Power
- 0
I found the problem... I didn't put in the brakets beside my letters. The regex should go like follow: ^[a-z]{1,}$
Newb today, Pro tomorrow,
Soulmed
- 04-28-2011, 04:33 PM #5
'One or more times' is more conventionally written as '+'
Also, since you want to match repetition of a single character class (using matches -- not find) to the entire String, including the start and end of input are redundant.Java Code:^[a-z]+$
dbJava Code:[a-z]+
edit There's also a posix character class \p{Lower} which is equivalent to [a-z]. Read the documentation for Pattern.Last edited by DarrylBurke; 04-28-2011 at 04:39 PM.
- 04-28-2011, 07:59 PM #6
Member
- Join Date
- Apr 2011
- Posts
- 11
- Rep Power
- 0
Similar Threads
-
RegEx
By watle in forum New To JavaReplies: 0Last Post: 03-22-2011, 08:07 AM -
need help with regex
By o2a1 in forum New To JavaReplies: 3Last Post: 02-13-2011, 12:53 AM -
Please Help - Regex
By BeeGee in forum Advanced JavaReplies: 0Last Post: 04-28-2010, 05:28 PM -
Help with regex
By SteroidalPsycho in forum New To JavaReplies: 2Last Post: 03-29-2010, 12:40 AM -
Using regex
By SteroidalPsycho in forum New To JavaReplies: 0Last Post: 03-28-2010, 11:07 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks