Reputation: 21
I have a string with some dates succeeded by a pattern FXTKLN.
JHSHSS20NOV2012 GHHSEE23FEB2011 FXTKLN
My requirement is to find the dates 20NOV2012, 23FEB2012 succeeded by the pattern FXTKLN and replace those dates with DATE20NOV2012DATE, DATE23FEB2012DATE and so on. There can be many dates - not just two.
Cheers, Pearl
Upvotes: 2
Views: 40
Reputation: 32797
find the dates 20NOV2012, 23FEB2012 succeeded by the pattern FXTKLN
Use this regex
\d{1,2}[a-zA-Z]{3}\d{4}(?=.*?FXTKLN)
The above regex
contains
\d{1,2}// matches 1 to 2 digits
[a-zA-Z]{3} //matches 3 characters
\d{4} //matches 4 digits
(?=.*?FXTKN) //checks if the date is followed by FXTKN considering multile dates before it!
I got to replace those dates with DATE20NOV2012DATE
Use this regex which now uses groups
(\d{1,2}[a-zA-Z]{3}\d{4})(?=.*?FXTKLN)
and then replace it with
DATE$1DATE
Upvotes: 1