Perl newbie regular expression usage question/help

D

dfairman16

Hi all

What I want my Perl programme to print out is

w
=
1
AND
(
(
x.y
=
"FRED ("
)
OR
(
z
=
2
)
)


generated from

w =1 AND ( (x.y="Fred (") OR (z=2) )

The problem is that although Perl and regular expressions are suitable
for the task, my starting point is that I have to learn Perl ... well
I'm learning it anyway, slowly, and the only thing that appears simple
is Hello World. Regular expressions are really complex, more than I
had thought. The bit the regular expression I am trying to use above
is that I don't care about spaces except for when they are enclosed by
double quotes (the "FRED (" bit in the query example above).


The query above is a real cut down simple version of the query string
that I would like to start to work on. The real query is a lot more
complex but I want to get it working for a very simple one first, then
extend the Perl, and during extending it learn more of the subset of
Perl I need to know to get it all done.

At the risk of being accused of asking someone to do my project for
me, as above is a starting point I would really appreciate being
pointed in the right direction. Not that it should matter but I
include the information for completeness, I am using Perl 5.8.8 on
Suse linux 8.

Thank you
David Fairman
UK


ps. I don't clear my email from this email account so reply in this
newsgroup. This email address is just one I use to stop me getting
spam at home.
 
J

Jürgen Exner

What I want my Perl programme to print out is

w
=
1
AND
(
(
x.y
=
"FRED ("
)
OR
(
z
=
2
)
)

generated from

w =1 AND ( (x.y="Fred (") OR (z=2) )

It appears like you want to split the line at spaces:
split (/\s*/, 'w =1 AND ( (x.y="Fred (") OR (z=2)');
This is assuming that the non-split "FRED (" was an oversight in your sample
result above.

jue
 
D

dfairman16

It appears like you want to split the line at spaces:
split (/\s*/, 'w =1 AND ( (x.y="Fred (") OR (z=2)');
This is assuming that the non-split "FRED (" was an oversight in your sample
result above.

jue- Hide quoted text -

- Show quoted text -


Thanks for your help Jürgen. I almost had something similar to what
you wrote in my Perl regular expression. The "FRED (" was not an
oversight however - the token I want is "FRED (" and including the
spaces. This is my big problem, spaces everythere except for between
quotes should be treated as just white space, in quotes they are not.

Thank you

David
 
D

dfairman16

Thanks for your help Jürgen. I almost had something similar to what
you wrote in my Perl regular expression. The "FRED (" was not an
oversight however - the token I want is "FRED (" and including the
spaces. This is my big problem, spaces everythere except for between
quotes should be treated as just white space, in quotes they are not.

Thank you

David- Hide quoted text -

- Show quoted text -

Oh, and the quotes should be part of the token too, ie. they shouldn't
be discarded.
 
T

Tad McClellan

the token I want is "FRED (" and including the
spaces. This is my big problem, spaces everythere except for between
quotes should be treated as just white space, in quotes they are not.


Now you have a Question that is Asked Frequently:

How can I split a [character] delimited string except when
inside [character]?
 
D

dfairman16

the token I want is "FRED (" and including the
spaces. This is my big problem, spaces everythere except for between
quotes should be treated as just white space, in quotes they are not.

Now you have a Question that is Asked Frequently:

How can I split a [character] delimited string except when
inside [character]?

OK, the link is

http://www.perl.com/doc/FAQs/FAQ/oldfaq-html/Q4.28.html

I'm glad
1. You haven't come down on me with wrath
2. I mentioned out the outset I'm learning <g>

Thank you
David.
 
G

Gunnar Hjalmarsson

What I want my Perl programme to print out is

w
=
1
AND
(
(
x.y
=
"FRED ("
)
OR
(
z
=
2
)
)

generated from

w =1 AND ( (x.y="Fred (") OR (z=2) )

local $_ = 'w =1 AND ( (x.y="Fred (") OR (z=2) )';
print "$_\n" for /".*?"|\w+\.\w+|\w+|\S/g;
 
T

Tad McClellan

the token I want is "FRED (" and including the
spaces. This is my big problem, spaces everythere except for between
quotes should be treated as just white space, in quotes they are not.

Now you have a Question that is Asked Frequently:

How can I split a [character] delimited string except when
inside [character]?


[ it is poor netiquette to quote .sigs ]

2. I mentioned out the outset I'm learning <g>


You do not need a link.

The Perl FAQ is installed on your own hard disk as part of
a normal perl install.

The docs (including the FAQ) installed with your perl will be
better than what you can find on the web, because it will be
specific to the version of perl that you are actually using.
 

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

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top