Matching fields of column in table

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
zackushka
Forum Newbie
Posts: 2
Joined: Mon Aug 31, 2009 2:17 am

Matching fields of column in table

Post by zackushka »

Matching fields of column in table (columns are separated by tab) using Regex

I have txt file:

Company Symb Exchange Date
COCA-COLA Inc. COCA NASDAQ 01.01.1980
Microsoft Inc. MSFT SMART 01.01.1987
Dell Inc. DELL EXCH2 01.01.1990
Samsung Inc. Sams NASDAQ 01.01.1992
Google Inc. Gle EXCH,EXCH2 06.02.1991
Yandex Inc. ya SMART,NASDAQ,EXCH,EXCH2 02.03.1997
Meta Inc. Mta SMART,EXCH 04.04.1998
JET Inc. Jt EXCH,SMART,NASDAQ 05.05.2000
A4Tech Inc. A4 NASDAQ,EXCH2 06.08.1990
Yahoo! Inc. Y! NASDAQ,SMART,EXCH 09.03.1998
Levi's L's SMART,EXCH3,EXCH4 02.05.2000
Disney D. NASDAQ,SMART4,SMART5,SMART6 04.05.1980



This file represent simple table. I have four columns: Company, Symb, Exchange and Date.

Fields beetween columns separated by tab (\t)

Please help me match all fields for 1st, 2nd, 3rd and 4th column, using regex template.

THX.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Matching fields of column in table

Post by Benjamin »

Why not explode each line on tabs?
zackushka
Forum Newbie
Posts: 2
Joined: Mon Aug 31, 2009 2:17 am

Re: Matching fields of column in table

Post by zackushka »

astions wrote:Why not explode each line on tabs?
plz explain, thanks
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: Matching fields of column in table

Post by Darhazer »

Code: Select all

$line = COCA-COLA Inc. COCA NASDAQ 01.01.1980; // probably read by file
list($company, $symb, $exchange, $date) = explode("\t", $line);
No need of regexpression for such simple templates
Post Reply