• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help with Regular Expression

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,

I have a file name of the following format "Titan20110801P96584" . Now i want to split the filename using a regular expression and drop the date part in the file name.

I tried the regular expression [\\d] , but that drops all the numbers , but I only want to drop the 20110801 from the file name , and retain the rest.

Can anybody help.

Thanks in advance,
Vivek
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which part is the date part?

The trick to coming up with the regular expression is to know what you are trying to get. How would you tell someone, who had no idea what a date was, what part you want to keep and what part you want to get rid of?
 
Vivek Sam
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

The date part is 20110801 .

Now if I had to tell somebody who had no idea what a date was , I would want to keep the first text part of the filename till I encounter the first number , and then skip the numbers which follow the the format YYYY-MM-DD , and then pick up the rest of the characters after that to give me the final name as TitanP96584.

 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So you have a bunch of letters, then a bunch of digits, then some more stuff which starts with a letter. And you want to drop the bunch of digits. Is that right?

(I could also ask if you wanted to drop the bunch of digits even if they didn't represent a date, but let's not do that just yet.)
 
fred rosenberger
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know what a date is, so telling me "YYYY-MM-DD" doesn't mean anything. Further, I don't see any dashes in the file name, so what does that have to do with anything?
 
Greenhorn
Posts: 8
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Vivek Sam wrote:Hi,

The date part is 20110801 .

Now if I had to tell somebody who had no idea what a date was , I would want to keep the first text part of the filename till I encounter the first number , and then skip the numbers which follow the the format YYYY-MM-DD , and then pick up the rest of the characters after that to give me the final name as TitanP96584.


You could many Regex tools available online. See if this works for you.
\d{8}
I assumed the date format will always be of 8 numbers (YYYYMMDD) and the characters of the file-name [at beginning] (Titan) don't end with a number.
 
Vivek Sam
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Paul
Yes , thats right

@Fred
Ok , so generally speaking it would just be a sequence of digits that follow , and the length of which would not exceed 8 digits.
 
fred rosenberger
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
would it not exceed 8, or would it be exactly 8?

are you guaranteed a letter after the date, before the other numeric part?
 
Vivek Sam
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@fred
Yes , it would not be greater than 8 , and a letter will follow before the non-numeric character

@Bhavani
Thanks for the input , I will try and understand the same , and then refine it further to use it in my code
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic