regex - to simple to see?

J

Jerry Preston

I am trying to breakdown the following line:

SPLIT #1:--> XXXXXXX... .......... .....

^ ^^^^^^^^^^ ^^^^^^^^^ ^^^^^

I want the 1, XXXXXXX..., .......... and .....

I am using:

$line[ 0 ] =~ /SPLIT #(\d+):-->\s+(\w{10})\s+(\w{10})\s+(\w{5})/;

and I am only getting the "1". I do not see what I am doing wrong.

I know it is simple but what am I missing?



Thanks,



Jerry
 
J

Jerry Preston

OK!

$line[ 0 ] = "SPLIT #1:--> XXXXXXX... .......... .....";
This $line[ 0 ] =~ /SPLIT #(\d+):-->\s+(\w{7})/; gives
$1 = "XXXXXXX", but I need to get all of the "." as well.
I know the X & . any combination are in the lengths of 10, 10 and 5.
Sometimes there are space in the blocks.

Why can I not get the "." included ?

Thanks,

Jerry
 
J

Jerry Preston

OK!

This works great!!!

$line[ 0 ] =~ /SPLIT
#(\d+):-->\s+([\w|\W]{10})\s+([\w|\W]{10})\s+([\w|\W]{5})/;

Jerry


Jerry Preston said:
OK!

$line[ 0 ] = "SPLIT #1:--> XXXXXXX... .......... .....";
This $line[ 0 ] =~ /SPLIT #(\d+):-->\s+(\w{7})/; gives
$1 = "XXXXXXX", but I need to get all of the "." as well.
I know the X & . any combination are in the lengths of 10, 10 and 5.
Sometimes there are space in the blocks.

Why can I not get the "." included ?

Thanks,

Jerry

Jerry Preston said:
I am trying to breakdown the following line:

SPLIT #1:--> XXXXXXX... .......... .....

^ ^^^^^^^^^^ ^^^^^^^^^ ^^^^^

I want the 1, XXXXXXX..., .......... and .....

I am using:

$line[ 0 ] =~ /SPLIT #(\d+):-->\s+(\w{10})\s+(\w{10})\s+(\w{5})/;

and I am only getting the "1". I do not see what I am doing wrong.

I know it is simple but what am I missing?



Thanks,



Jerry
 
A

A. Sinan Unur

$line[ 0 ] = "SPLIT #1:--> XXXXXXX... .......... .....";
This $line[ 0 ] =~ /SPLIT #(\d+):-->\s+(\w{7})/; gives
$1 = "XXXXXXX", but I need to get all of the "." as well.
I know the X & . any combination are in the lengths of 10, 10 and 5.
Sometimes there are space in the blocks.


use strict;
use warnings;

use Data::Dumper;

my $s = 'SPLIT #1:--> XXXXXXX... .......... .....';

my @matches = ($s =~ /^SPLIT #(\d+):-->\s+(\S+)\s+(\S+)\s+(\S+)\s*$/);
print Dumper \@matches;

D:\Home> perl t.pl
$VAR1 = [
'1',
'XXXXXXX...',
'..........',
'.....'
];
Why can I not get the "." included ?

I am not sure. Are you forgetting that . is special in regexes?

Sinan.
 
A

A. Sinan Unur

$line[ 0 ] = "SPLIT #1:--> XXXXXXX... .......... .....";
This $line[ 0 ] =~ /SPLIT #(\d+):-->\s+(\w{7})/; gives
$1 = "XXXXXXX", but I need to get all of the "." as well.
I know the X & . any combination are in the lengths of 10, 10 and 5.
Sometimes there are space in the blocks.

I missed the last sentence above in my response before.

use strict;
use warnings;

use Data::Dumper;

my $s = 'SPLIT #1:--> XXXX XX... .......... .....';

my @matches = ($s =~ /^SPLIT #(\d+):-->\s+(.{10})\s+(.{10})\s+(.{5})\s*$/);
print Dumper \@matches;

__END__

D:\Home> perl t.pl
$VAR1 = [
'1',
'XXXX XX...',
'..........',
'.....'
];


Sinan.
 
G

gnari

Jerry Preston said:
OK!

This works great!!!

$line[ 0 ] =~ /SPLIT
#(\d+):-->\s+([\w|\W]{10})\s+([\w|\W]{10})\s+([\w|\W]{5})/;

\w means a word character (no fullstops or spaces included)
\W means characters that are not in \w
[\w\W] means any character
[\w|\W] means any character and doubly so if |
.. means any character
..{10} means any 10 characters

so :
#(\d+):-->\s+(.{10})\s+(.{10})\s+(.{5})/;


gnari
 
A

Arndt Jonasson

Jerry Preston said:
I am trying to breakdown the following line:

SPLIT #1:--> XXXXXXX... .......... .....

^ ^^^^^^^^^^ ^^^^^^^^^ ^^^^^

I suppose the above line is an attempt to show which parts of the
input line you're interested in extracting. Note that if you use
tab characters and/or a proportional font when you're writing, what
looks good to you may turn out wrong when others read it.
(If others use a proportional font when reading, that is not your
fault, of course.)

The below is what looks good for a fixed-width font:
 
G

Gerhard M

Jerry Preston said:
I am using:

$line[ 0 ] =~ /SPLIT #(\d+):-->\s+(\w{10})\s+(\w{10})\s+(\w{5})/;

and I am only getting the "1". I do not see what I am doing wrong.

What are you doing?
if ($line[0] =~ /..../) ...

Do you use $1...$4 or maybe @list=($line[0]=~/.../)?
So please provide some more code.

Gerhard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,164
Messages
2,570,901
Members
47,439
Latest member
elif2sghost

Latest Threads

Top