aspose file tools*
The moose likes Beginning Java and the fly likes Regular Expression Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Regular Expression" Watch "Regular Expression" New topic
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: 378
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: 19783
    
  20

[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 - OCEEJBD 6
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: 19060
    
  40

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: 378
That's pretty good. This will possessively match all non digits.

Does that match your requirement Pawan?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Regular Expression