R
Robin
I dunno, would this match only white space: / */ . ... ?
or would it match somethin else with the white space?
or would it match somethin else with the white space?
Robin said:I dunno, would this match only white space: / */ . ... ?
or would it match somethin else with the white space?
What happened when you tried it?
use strict;
use warnings;
my @strings = (' ', ' another', 'another one', 'o n e m o r e');
for (@strings) {
print "$_: matched\n" if / */;
}
I dunno, would this match only white space: / */ . ... ?
or would it match somethin else with the white space?
Robin said:I dunno, would this match only white space: / */ . ... ?
or would it match somethin else with the white space?
No. It matches zero or more occurences of a space character. To match
white space, use \s, which includes tabs, newlines, and other
characters along with literal space characters.
See also:
perldoc perlretut
It occurs to me that you've often been told "perldoc this", but may
not have been told what "perldoc" is...
"perldoc" is a utility that's used to view the documentation that's
bundled with Perl. To use it, open up a terminal window and type
"perldoc whatever". Some good places to start are "perldoc perlfaq",
"perldoc perl", and "perldoc intro". The same documentation can also
be found in HTML format at <http://www.perldoc.com>.
I *think* perldoc is available on WinDOS systems too, but I don't have
one handy to check.
....
....
....
If (s)he finds it inconvenient to read the perldocs in the dos window,
perldoc whatever >whatever.txt
dumps the output of the 'perldoc whatever' into whatever.txt for
printing / bathroom reading / etc.
Jürgen Exner said:Why do you think a plain blank character would match any arbitrary white
space?
If you want to match white space then say so
/\s*/
For further details please Read The Fine Manual: perldoc perlre
Jürgen Exner said:Why do you think a plain blank character would match any arbitrary white
space?
If you want to match white space then say so
/\s*/
For further details please Read The Fine Manual: perldoc perlre
Robin said:I dunno, would this match only white space: / */ . ... ?
Marc Bissonnette said:If (s)he finds it inconvenient to read the perldocs in the dos window,
perldoc whatever >whatever.txt
dumps the output of the 'perldoc whatever' into whatever.txt for printing
/ bathroom reading / etc.
Robin said:PS. I don't like being killfiled and flamed,
Matt Garrish said:Everyone seems to be missing a fundemental point about optional content:
my $line = 'IHAVENOWHITESPACE';
if ($line =~ /\s*/) {
print "D'oh!";
}
Anno Siegel said:So? It still didn't match anything but spaces.
Matt Garrish said:The spaces between spaces, I suppose, but not what the OP wanted to know
(and not \s solutions that have been posted). Writing a regex with nothing
but optional content is just pointless in so many ways it boggles my poor
mind...
Anno Siegel said:As a stand-alone regex it wouldn't do much, though with /g it may serve
a purpose. As part of a larger regex it is perfectly useful.
I'm not sure what the OPs original question was.
Matt Garrish said:True enough, though I personally can't think of any reason why you would
want to match/count these "spaces" in a string (but I suppose everything has
its purpose). length() would be the function most people would be looking
for, or so I would assume, as a count based on an optional pattern like the
above will always return the actual length plus one (that pesky "space" at
the beginning of the string).
Do the pod2* converters (eg: pod2html) work?
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.