views:

43

answers:

4

Hi,

I'm trying to split the following: 2010-07-30 10:10:50

and I would like to ONLY end up with:

2010

07

30

normally with just the date, you regex with /-/

however now I would like something as simple as that but now i get

2010

07

30 10:10:50

how can i get that last part + space out?

Thank you so much!

ps, right now I need this in PHP but later on I also need to implement this in JAVA

A: 

The answer that has just been deleted worked like a charm, /[- ]/

it did the trick in PHP and will probably also in JAVA.

Paintrick
A: 

As Mark said it depends upon the programming lanuage: i can think of awk this way:

echo "2010-07-30 10:10:50"|awk -F'-' '{split($3,a," ");print $1,$2,a[1]}'
Vijay Sarathi
A: 

Well I dont know which language you are using, but you can use below regex to match the numbers of your interest as you described

\b\d+\b(?=(\s|-)) 

What this effectively does is find the numbers ending either with space or with a hypen

Gopi
+1  A: 

Use split on [- ] :

In perl, i think it's easy to transpose in other language.

my $s =q!2010-07-30 10:10:50!;
my @l = split/[- ]/,$s;
$" = $/;
print "@l";

output:

2010
07
30 
10:10:50
M42