Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Help with a Reg Ex

Reply
Thread Tools

Help with a Reg Ex

 
 
amerar@iwc.net
Guest
Posts: n/a
 
      01-09-2008

I have the following expression in my Perl script:

if (/^"([^\,].+)"\,"$/)

Although I know that it is checking to see if the string starts with
some characters, it is not working for my input file.

Can someone explain to me in english what it is doing???

Thanks in advance.
 
Reply With Quote
 
 
 
 
Martijn Lievaart
Guest
Posts: n/a
 
      01-09-2008
On Wed, 09 Jan 2008 11:00:18 -0800, wrote:

> I have the following expression in my Perl script:
>
> if (/^"([^\,].+)"\,"$/)
>
> Although I know that it is checking to see if the string starts with
> some characters, it is not working for my input file.
>
> Can someone explain to me in english what it is doing???


/
^ # beginning of string
" # match a quote
( # start capturing
[^\,] # one of any character, except comma
.+ # one of more of any character, except newline
) # stop capturing
" # another quote
\, # a comma
" # yet another quote
$ # end of string
/x

In other words, any string that starts with a quote; then two or more
characters, but not starting with a comma; a quote; a comma and a quote.

What do you want to achieve?

M4
 
Reply With Quote
 
 
 
 
amerar@iwc.net
Guest
Posts: n/a
 
      01-09-2008
On Jan 9, 2:39 pm, Martijn Lievaart <m...@rtij.nl.invlalid> wrote:
> On Wed, 09 Jan 2008 11:00:18 -0800, ame...@iwc.net wrote:
> > I have the following expression in my Perl script:

>
> > if (/^"([^\,].+)"\,"$/)

>
> > Although I know that it is checking to see if the string starts with
> > some characters, it is not working for my input file.

>
> > Can someone explain to me in english what it is doing???

>
> /
> ^ # beginning of string
> " # match a quote
> ( # start capturing
> [^\,] # one of any character, except comma
> .+ # one of more of any character, except newline
> ) # stop capturing
> " # another quote
> \, # a comma
> " # yet another quote
> $ # end of string
> /x
>
> In other words, any string that starts with a quote; then two or more
> characters, but not starting with a comma; a quote; a comma and a quote.
>
> What do you want to achieve?
>
> M4


Basically I have an input file, and the result of that IF statement
decides if I process the line read of not.......

 
Reply With Quote
 
amerar@iwc.net
Guest
Posts: n/a
 
      01-09-2008
On Jan 9, 2:39 pm, Martijn Lievaart <m...@rtij.nl.invlalid> wrote:
> On Wed, 09 Jan 2008 11:00:18 -0800, ame...@iwc.net wrote:
> > I have the following expression in my Perl script:

>
> > if (/^"([^\,].+)"\,"$/)

>
> > Although I know that it is checking to see if the string starts with
> > some characters, it is not working for my input file.

>
> > Can someone explain to me in english what it is doing???

>
> /
> ^ # beginning of string
> " # match a quote
> ( # start capturing
> [^\,] # one of any character, except comma
> .+ # one of more of any character, except newline
> ) # stop capturing
> " # another quote
> \, # a comma
> " # yet another quote
> $ # end of string
> /x
>
> In other words, any string that starts with a quote; then two or more
> characters, but not starting with a comma; a quote; a comma and a quote.
>
> What do you want to achieve?
>
> M4


I might add, the input file looks like this:

"#ABC","
[
","ABC Dispensing designs, manufactures and services dispensing
systems that utilize standard micro-processing technology and
proprietary operating software.","
]
"
"#ABE","
[
","Aber Diamond Corporation is a specialist diamond company focusing
on the mining and retail segments of the diamond industry. The Company
supplies rough diamonds to the global market through its forty percent
ownership in the Diavik Diamond Mine and owns one of the world's
premier retailers of diamond jewelry, Harry Winston.","
]
"

And I guess it is deciding if the line needs to be processed.......



 
Reply With Quote
 
Jürgen Exner
Guest
Posts: n/a
 
      01-09-2008
"" <> wrote:
>
>I have the following expression in my Perl script:
>
>if (/^"([^\,].+)"\,"$/)
>
>Although I know that it is checking to see if the string starts with
>some characters, it is not working for my input file.
>
>Can someone explain to me in english what it is doing???


Match a string that
^ starts with
" a double quote
( and then a group that consists of
[^\,] one of the three characters caret, backslash, comma
..+ followed by at least one more character
)
"\," and has the character sequence double quote, comma, doublequote
$ at the end of the string.

I hope I got that right.

jue
 
Reply With Quote
 
Jürgen Exner
Guest
Posts: n/a
 
      01-09-2008
Jürgen Exner <> wrote:
>"" <> wrote:
>>
>>I have the following expression in my Perl script:
>>
>>if (/^"([^\,].+)"\,"$/)
>>
>>Although I know that it is checking to see if the string starts with
>>some characters, it is not working for my input file.
>>
>>Can someone explain to me in english what it is doing???

>
>Match a string that
>^ starts with
>" a double quote
>( and then a group that consists of
>[^\,] one of the three characters caret, backslash, comma


Ooops, correction. Make that
[^\,] any single character, that is not backslash or comma

>.+ followed by at least one more character
>)
>"\," and has the character sequence double quote, comma, doublequote
>$ at the end of the string.
>
>I hope I got that right.
>
>jue

 
Reply With Quote
 
John W. Krahn
Guest
Posts: n/a
 
      01-09-2008
Jürgen Exner wrote:
> Jürgen Exner <> wrote:
>> "" <> wrote:
>>> I have the following expression in my Perl script:
>>>
>>> if (/^"([^\,].+)"\,"$/)
>>>
>>> Although I know that it is checking to see if the string starts with
>>> some characters, it is not working for my input file.
>>>
>>> Can someone explain to me in english what it is doing???

>> Match a string that
>> ^ starts with
>> " a double quote
>> ( and then a group that consists of
>> [^\,] one of the three characters caret, backslash, comma

>
> Ooops, correction. Make that
> [^\,] any single character, that is not backslash or comma


You were right the first time. A backslash before a normal character in
a double quoted string is superfluous.

$ perl -le'print qr/[^\,]/'
(?-xism:[^,])



John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
 
Reply With Quote
 
John W. Krahn
Guest
Posts: n/a
 
      01-09-2008
Jürgen Exner wrote:
> Jürgen Exner <> wrote:
>> "" <> wrote:
>>> I have the following expression in my Perl script:
>>>
>>> if (/^"([^\,].+)"\,"$/)
>>>
>>> Although I know that it is checking to see if the string starts with
>>> some characters, it is not working for my input file.
>>>
>>> Can someone explain to me in english what it is doing???

>> Match a string that
>> ^ starts with
>> " a double quote
>> ( and then a group that consists of
>> [^\,] one of the three characters caret, backslash, comma

>
> Ooops, correction. Make that
> [^\,] any single character, that is not backslash or comma


A backslash before a normal character in a double quoted string is
superfluous.

$ perl -le'print qr/[^\,]/'
(?-xism:[^,])



John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
 
Reply With Quote
 
Martijn Lievaart
Guest
Posts: n/a
 
      01-09-2008
On Wed, 09 Jan 2008 20:40:49 +0000, Jürgen Exner wrote:

> Jürgen Exner <> wrote:
>>"" <> wrote:
>>>
>>>I have the following expression in my Perl script:
>>>
>>>if (/^"([^\,].+)"\,"$/)
>>>
>>>Although I know that it is checking to see if the string starts with
>>>some characters, it is not working for my input file.
>>>
>>>Can someone explain to me in english what it is doing???

>>
>>Match a string that
>>^ starts with
>>" a double quote
>>( and then a group that consists of
>>[^\,] one of the three characters caret, backslash,

comma
>
> Ooops, correction. Make that
> [^\,] any single character, that is not backslash or

comma

No, is not comma:

[martijn@dexter ~]$ perl -e 'print "yes\n" if "," =~ /[^\,]/'
[martijn@dexter ~]$ perl -e 'print "yes\n" if "\\" =~ /[^\,]/'
yes
[martijn@dexter ~]$

HTH,
M4
 
Reply With Quote
 
Martijn Lievaart
Guest
Posts: n/a
 
      01-09-2008
On Wed, 09 Jan 2008 12:06:35 -0800, wrote:

> On Jan 9, 2:39 pm, Martijn Lievaart <m...@rtij.nl.invlalid> wrote:
>> On Wed, 09 Jan 2008 11:00:18 -0800, ame...@iwc.net wrote:
>> > I have the following expression in my Perl script:

>>
>> > if (/^"([^\,].+)"\,"$/)


(snip)

> I might add, the input file looks like this:
>
> "#ABC","
> [
> ","ABC Dispensing designs, manufactures and services dispensing systems

(snip)

Yes, that regex will match the first line.

$ perl -e 'print "yes\n" if "\"#ABC\",\"" =~ /^"([^\,].+)"\,"$/'
yes

(Note extra backslashes in the input line because this is executed from
the commandline)

BTW, the backslashes before the commas are completely unneeded.

$ perl -e 'print "yes\n" if "\"#ABC\",\"" =~ /^"([^,].+)","$/'
yes

HTH,
M4
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Windows Reg Pro vs Tweak now Reg Cleaner vs Registry fix, vs RegCleaner jl Computer Support 3 05-31-2005 12:53 AM
Help needed with reg exp please Aristotle Perl 4 09-04-2004 05:38 PM
Reg Ex Help for a Lazy VB Programmer adams114@comcast.net Perl 6 04-21-2004 08:27 PM
Reg Exp Help PerlE Perl 0 01-30-2004 06:15 AM
Reg: Help me out pls... RamaKrishna ASP .Net 0 08-18-2003 11:42 AM



Advertisments