• Post Reply Bookmark Topic Watch Topic
  • New Topic

regex problem!!!  RSS feed

 
James Basller
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am very new to regex. I know that it's used for matching patterns. But I want to know that is there anything in regex which can substring my string. I don't want to use String's substring function.

For example,

if I have a string 1234567890123456. In this 16 length char string I just want only last 6 chars.

Can I do this with regex? If yes can anyone provide me solution???

Thanks!!!
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't want to use String's substring function.

Why not? It would be the natural (and easiest) solution for this.
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Although I agree with Ulf, I'll help you out nonetheless.

Do you know how to match one digit?
Do you know how to match six digits?
Do you know how to match the end of input?

Combine those, and there is your regular expression: 6 digits directly followed by the end of input.
 
James Basller
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:
I don't want to use String's substring function.

Why not? It would be the natural (and easiest) solution for this.


Hi,

I will go for String operations.....

Thank you all.....

 
krishna bala
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!