Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   regular expression help with apostrophe (http://www.velocityreviews.com/forums/t891351-regular-expression-help-with-apostrophe.html)

dmalhotr2001@yahoo.com 03-15-2005 02:31 AM

regular expression help with apostrophe
 
Hi,

I would like to figure out a certain issue.

I have a regular expression [^\']+ that checks whether there's a
apostrophe in a particular string. In my case I'm using a file path
and filename so for example.

C:\Documents and Settings\test_user\Local Settings\Temporary Internet
Files\Content.IE5\testing.html

Now this works to check if there is an apostrophe.

However I don't know how to check ONLY if there is an apostrophe in the
file name, meaning if there is a apostrophe in testing.html example
above. I would want it to ignore it if Local's Settings folder has an
apostrophe.

Thus, what regular expression would yield an apostrophe just in the
filename at the end and would ignore apostrophes in the folder paths.

Thanks in advance.

:D


Bob Walton 03-15-2005 03:32 AM

Re: regular expression help with apostrophe
 
dmalhotr2001@yahoo.com wrote:

....
> I have a regular expression [^\']+ that checks whether there's a
> apostrophe in a particular string. In my case I'm using a file path
> and filename so for example.
>
> C:\Documents and Settings\test_user\Local Settings\Temporary Internet
> Files\Content.IE5\testing.html
>
> Now this works to check if there is an apostrophe.
>
> However I don't know how to check ONLY if there is an apostrophe in the
> file name, meaning if there is a apostrophe in testing.html example
> above. I would want it to ignore it if Local's Settings folder has an
> apostrophe.
>
> Thus, what regular expression would yield an apostrophe just in the
> filename at the end and would ignore apostrophes in the folder paths.


Well, it isn't too clear what you want. I have assumed you want
a regexp that will match if a Windoze path and file name has no
apostrophe in the filename portion, and will fail to match if the
filename portion of the path and file name contains one or more
apostrophes. If that is correct, try:

use warnings;
use strict;
while(<DATA>){
chomp;
/(?:.*\\|^)[^']+$/
?
print "$_ has no apostrophe in filename\n"
:
print "$_ has at least one apostrophe in filename\n";
}
__END__
c:\no apostrophe\here.ext
c:\one ' apostrophe\here.ext
c:\file\has\apost'rophe.ext
justa.file
c:\justa.file
c:\just'a.f'''''ile
c:'\justa.file
path\file'''''.ext
just a path\

....

> :D

--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl

Tad McClellan 03-15-2005 04:18 AM

Re: regular expression help with apostrophe
 
dmalhotr2001@yahoo.com <dmalhotr2001@yahoo.com> wrote:

> I have a regular expression [^\']+ that checks whether there's a
> apostrophe in a particular string.



Single quotes are not special, there is no need to backslash them.


> I would want it to ignore it if Local's Settings folder has an
> apostrophe.



What is a Local's Settings folder?


> Thus, what regular expression would yield an apostrophe



None.

Regular expressions do not "yield" characters.

They either match (succeed), or they don't match (fail).


--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas

Walter Roberson 03-15-2005 05:26 AM

Re: regular expression help with apostrophe
 
In article <slrnd3cog8.52n.tadmc@magna.augustmail.com>,
Tad McClellan <tadmc@augustmail.com> wrote:
:dmalhotr2001@yahoo.com <dmalhotr2001@yahoo.com> wrote:

:> I have a regular expression [^\']+ that checks whether there's a
:> apostrophe in a particular string.

:Single quotes are not special, there is no need to backslash them.

There is if you are using perl -e '...' or if you are constructing
a single-quoted string that will be extrapolated into a pattern.

The first of these is, of course, an artifact of shell quoting
conventions; the second is perl itself. You can use the
q{} or qw{} operators though... which changes the delimeter
but does not evade the fact that there will be -some- character
you have to escape if it appears in the string.
--
Entropy is the logarithm of probability -- Boltzmann

Fabian Pilkowski 03-15-2005 08:37 AM

Re: regular expression help with apostrophe
 
* Bob Walton wrote:

> Well, it isn't too clear what you want. I have assumed you want
> a regexp that will match if a Windoze path and file name has no
> apostrophe in the filename portion, and will fail to match if the
> filename portion of the path and file name contains one or more
> apostrophes. If that is correct, try:
>
> use warnings;
> use strict;
> while(<DATA>){
> chomp;
> /(?:.*\\|^)[^']+$/
> ?
> print "$_ has no apostrophe in filename\n"
> :
> print "$_ has at least one apostrophe in filename\n";
> }
> __END__
> just a path\


If your string could be "just'a'path\" then your code will say there is
"at least one apostrophe in filename" -- but it's just a path without a
filename ;-)

Hence, I'd change the latter + in your regex to *, so that it could
match on empty filenames too.

regards,
fabian

Peter Wyzl 03-15-2005 12:30 PM

Re: regular expression help with apostrophe
 
"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrnd3cog8.52n.tadmc@magna.augustmail.com...
> dmalhotr2001@yahoo.com <dmalhotr2001@yahoo.com> wrote:
>
> > I have a regular expression [^\']+ that checks whether there's a
> > apostrophe in a particular string.

>
>
> Single quotes are not special, there is no need to backslash them.
>
>
> > I would want it to ignore it if Local's Settings folder has an
> > apostrophe.

>
>
> What is a Local's Settings folder?


That is like asking "What is a /usr/var directory?"

Whilst not a direct equivalent, it is a common enough environment to be
accepted as known by any competent windows user.

Never mind. I think the question is just as valid without the specific
example,

"How do I tell if the filename part of the string has a single quote, and
ignore the rest of the pathname?"

....

use File::Basename;

is a good start...

P



phaylon 03-15-2005 12:38 PM

Re: regular expression help with apostrophe
 
Peter Wyzl wrote:

> That is like asking "What is a /usr/var directory?"


Wouldn't say "/usr/var" is a "fully qualified" pathname. "Local Settings
Folder" is not.

> Whilst not a direct equivalent, it is a common enough environment to be
> accepted as known by any competent windows user.


Some people haven't seen Windows for a long time :D

--
http://www.dunkelheit.at/
...and in darkness bind them.


Tad McClellan 03-15-2005 01:43 PM

Re: regular expression help with apostrophe
 
Peter Wyzl <wyzelli@yahoo.com> wrote:
> "Tad McClellan" <tadmc@augustmail.com> wrote in message
> news:slrnd3cog8.52n.tadmc@magna.augustmail.com...
>> dmalhotr2001@yahoo.com <dmalhotr2001@yahoo.com> wrote:



>> > I would want it to ignore it if Local's Settings folder has an
>> > apostrophe.

>>
>>
>> What is a Local's Settings folder?

>
> That is like asking "What is a /usr/var directory?"
>
> Whilst not a direct equivalent, it is a common enough environment to be
> accepted as known by any competent windows user.



But I am an incompetent windows user, so I though I might
learn some(off-topic)thing:

Does windows have a way to specify the characters allowed in pathnames?

That's what it sounded like to me...


--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas

dmalhotr2001@yahoo.com 03-15-2005 05:08 PM

Re: regular expression help with apostrophe
 
Jesus christ,

You guys are overthinking this to death. keep the thing simple

c:\testing's folder\filename.ext

I want a regular expression to ignore the above because - testing's
folder is a directory.

But if its:

C:\testing folder\what's_up.ext

I want the regular expression to yield.

Any questions??


A. Sinan Unur 03-15-2005 05:16 PM

Re: regular expression help with apostrophe
 
dmalhotr2001@yahoo.com wrote in news:1110906507.977082.212230
@g14g2000cwa.googlegroups.com:

> Jesus christ,
>
>
> You guys are overthinking this to death.


And you are in a position to judge how?

> keep the thing simple
>
> c:\testing's folder\filename.ext
>
> I want a regular expression to ignore the above because - testing's
> folder is a directory.


Here is what you originally stated:

<blockquote>
I have a regular expression [^\']+ that checks whether there's a
apostrophe in a particular string. In my case I'm using a file path
and filename so for example.
</blockquote>

The requirement you set out in this message does not match the original
requirement.

In any case, Peter pointed you to File::Basename. Have you not read the
documentation for that module yet.

Using that module, split the string into the various components. You
will be interested in one of those components I presume. Then, check if
that string contains an apostrophe.

If you are only interested in the existence of a single character in a
string, you should also look at:

perldoc -f index

> I want the regular expression to yield.
>
> Any questions??


*PLONK*


All times are GMT. The time now is 07:33 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.