| Author |
Regular Expression
|
Pawan Arora
Ranch Hand
Joined: Sep 14, 2008
Posts: 105
|
|
In the above program I want the output as yeargs ago, he used to be bad. But it is returning no output to me. Can anybody tell me how could I get my relevant answer, and what's the flaw this programme has to be not be able to returned the desirable result.
|
 |
Gamini Sirisena
Ranch Hand
Joined: Aug 05, 2008
Posts: 347
|
|
Pawan, Do you mean you want the output to be years ago, he used to be bad. ? You seem to have missed matching the white spaces.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
[a-zA-Z]+\\,\\. That means 1 or more letters, followed by a comma and a dot. Now I doubt there will ever be a proper sentence that ends in comma-dot. And where is the whitespace in your regex?
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Pawan Arora
Ranch Hand
Joined: Sep 14, 2008
Posts: 105
|
|
I have tried another way but I'm not yet getting any output. CAn anybody please tell me what's wrong in this particular expression? [ November 21, 2008: Message edited by: Pawan Arora ]
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16695
|
|
CAn anybody please tell me what's wrong in this particular expression?
Your pattern is some whitespaces, some letters, a comma, some white spaces, some letters, and a period... You are getting nothing back because it doesn't match your string. Now, if your string had been "90 ago, bad.", then it would have removed the 90 -- and returned the rest. Henry [ November 21, 2008: Message edited by: Henry Wong ]
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
Piet Verdriet
Ranch Hand
Joined: Feb 25, 2006
Posts: 266
|
|
[ November 22, 2008: Message edited by: Piet Verdriet ]
|
 |
Pawan Arora
Ranch Hand
Joined: Sep 14, 2008
Posts: 105
|
|
Thanks
|
 |
Gamini Sirisena
Ranch Hand
Joined: Aug 05, 2008
Posts: 347
|
|
That's pretty good. This will possessively match all non digits. Does that match your requirement Pawan?
|
 |
 |
|
|
subject: Regular Expression
|
|
|