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

 
 
Jürgen Exner
Guest
Posts: n/a
 
      01-09-2008
"John W. Krahn" <(E-Mail Removed)> wrote:
>Jürgen Exner wrote:
>> Jürgen Exner <(E-Mail Removed)> wrote:


>>> [^\,] 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.


Yes, but:
- this is not a double quoted string but a RE character class. So the
backslash would be taken literally ARAIR.
- My mistake was to not consider that ^ at the beginning of a character
class indicates the negation of that class.

jue
 
Reply With Quote
 
 
 
 
John W. Krahn
Guest
Posts: n/a
 
      01-09-2008
Martijn Lievaart wrote:
> On Wed, 09 Jan 2008 12:06:35 -0800, http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
>
>> On Jan 9, 2:39 pm, Martijn Lievaart <(E-Mail Removed)> wrote:
>>> On Wed, 09 Jan 2008 11:00:18 -0800, (E-Mail Removed) 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


Actually, none of the backslashes are really needed:

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



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:
> "John W. Krahn" <(E-Mail Removed)> wrote:
>> Jürgen Exner wrote:
>>> Jürgen Exner <(E-Mail Removed)> wrote:

>
>>>> [^\,] 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.

>
> Yes, but:
> - this is not a double quoted string but a RE character class. So the
> backslash would be taken literally ARAIR.


Unless the regular expression uses single quote delimiters the pattern
is first interpolated as if it were a double quoted string.

perldoc perlop

Read through the sections "Quote and Quote-like Operators", "Regexp
Quote-Like Operators" and "Gory details of parsing quoted constructs".



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
 
Tad J McClellan
Guest
Posts: n/a
 
      01-10-2008
(E-Mail Removed) <(E-Mail Removed)> 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???



Since you wrote it, you should be able to do that yourself.

Or did you mean "in someone else's Perl script" instead?




--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
 
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