• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regular Expression

 
Pawan Arora
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 378
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20493
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[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?
 
Pawan Arora
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 20881
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Piet Verdriet
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

[ November 22, 2008: Message edited by: Piet Verdriet ]
 
Pawan Arora
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
 
Gamini Sirisena
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's pretty good. This will possessively match all non digits.

Does that match your requirement Pawan?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic