Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regular expressions 1

Status
Not open for further replies.

blues77

Programmer
Jun 11, 2002
230
0
0
CA
Hello,

I'm having a little trouble creating a regular expression to extract some information from a string. Given the string

Column : Indv Clt Id ("COMP"."V01TPRFL_RLT_CLT""INDV_CLT_ID")

I want to extract the portions
Indv Clt Id
V01TPRL_RLT_CLT
INDV_CLT_ID

At the moment my regular expression looks like this
Code:
$_ =~ /Column\s*:\s*(.+)\s*\("COMP"\."(.+)""(.+)"/

This is the output being captured by this expression.
Label = Indv Clt Id
Table = TPRFL_RLT_CLT
Field = INDV_CLT_ID

It all looks ok except table should be V01TPRL_RLT_CLT. Can anyone tell me why I'm not capturing the entire string? Thanks for all your help!
 
I wish it did. But it should be assigning the string V01TPRL_RLT_CLT to the $2 variable but what I'm getting when I print out this variable is TPRFL_RLT_CLT. It's missing the V01.

 
This works with the sample text:
Code:
$_ = 'Column : Indv Clt Id  ("COMP"."V01TPRFL_RLT_CLT""INDV_CLT_ID")';
m/:\s*(.+\b)\s*\(.+\."(\w+)"+(\w+)/;
print "\|$1\|\n\|$2\|\n\|$3\|\n";
 
Thanks for your help rhash. I tried your regular exression alone and it works fine however when I use your expression in my code I'm still having the same problme. Here is my code.

Any ideas on why this isn't working? I'm very perplexed.

Code:
use strict;

open(SOURCE, $ARGV[0]);
open(LABELS, "labels.txt");
open(TABLES, "tables.txt");
open(COLUMNS, "columns.txt");


while (<SOURCE>)
{
	chomp;
	if($_ =~ m/:\s*(.+\b)\s*\(.+\."(\w+)"+(\w+)/)
	{
		print "Label = $1\n";
		print "Table = $2\n";
		print "Field = $3\n";
	}		
}

$_ = 'Column : Indv Clt Id  ("COMP"."V01TPRFL_RLT_CLT""INDV_CLT_ID")';
m/:\s*(.+\b)\s*\(.+\."(\w+)"+(\w+)/;
print "\|$1\|\n\|$2\|\n\|$3\|\n";



#Column : Indv Clt Id  ("COMP"."V01TPRFL_RLT_CLT""INDV_CLT_ID")
 
Are you certain the input is what you're expecting? Maybe post some more lines of data from your input file.
 
when i copy & paste code from this site - i often get weird spaces

my script will NOT run until i replace them with proper spaces

Maybe you are having a similar problem

try revealing invisible characters in your text editor

... just a thought


Kind Regards
Duncan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top