What's ^$ mean?

M

Mirco Wahab

Thus spoke Davy (on 2006-06-20 13:14):
Is ^$ mean a NULL line?

No, its usually used for detection of
"lines with no characters in them"
(only the logical line feed \n is there)
in /m mode of a regex.


Regards

Mirco
 
M

Mirco Wahab

Thus spoke Mirco Wahab (on 2006-06-20 13:25):
"lines with no characters in them"

A made up example of how you would use it:


use strict;
use warnings;

my $count = 0;
my $text= <<END_OF_TEXT;
A Line with something in it


two empty lines above!
(done)
END_OF_TEXT

print "empty line " . ++$count . " found\n"
for $text =~ /^$/gm; # <== here we go



Regards

Mirco
 
N

Nick of course

Mirco said:
Thus spoke Mirco Wahab (on 2006-06-20 13:25):


A made up example of how you would use it:


use strict;
use warnings;

my $count = 0;
my $text= <<END_OF_TEXT;
A Line with something in it


two empty lines above!
(done)
END_OF_TEXT

print "empty line " . ++$count . " found\n"
for $text =~ /^$/gm; # <== here we go



Regards

Mirco
A slightly shorter answer to the original question would have been "Yes"
 
D

Dr.Ruud

Davy schreef:
Is ^$ mean a NULL line?


Nice riddle!

Can I ask yes/no-questions? If yes:
Is you read the posting guidelines?

Show us the effective code that uses that "^$". Where does it fail?

If you want to learn to use regular expressions, read perlre and
friends.
 
J

Jürgen Exner

Davy said:
Is ^$ mean a NULL line?

In Perl a lot depends on context, e.g. scalar versus list context.
Therefore you will have to tell us at least a little bit about in which
context you stumbled across this character combination.

jue
 
T

Tad McClellan

Nick of course said:
Mirco Wahab wrote:

[snip full-quote]
A slightly shorter answer to the original question would have been "Yes"


That would have been a slightly shorter *wrong* answer.

(Since it will match when the string is "\n".)

The original (poorly phrased) question was:

Is ^$ mean a NULL line?

The OP didn't say where these characters are used. I'll guess they
are used with the pattern match operator.

What does "NULL line" mean?

I assume it means the "empty string" (in which case it cannot be
a "line" since it has no newline character).

So if a boolean response is required then "No" would be the accurate answer.

A more helpful answer would be:

/^$/ matches the empty string, or the 1-char long string where
the 1 char is a newline.
 
S

smarkham01

I don't disagree with your definition Tadd, but I'm curious as to what
meaning, other than "at the beginning of the (string | line) match the
end of (string | line)" "^$" might have? Don't meta-characters remain
remain meta-characters where ever they are, unless escaped of preceded
by \Q?



Tad said:
Nick of course said:
Mirco Wahab wrote:

[snip full-quote]
A slightly shorter answer to the original question would have been "Yes"


That would have been a slightly shorter *wrong* answer.

(Since it will match when the string is "\n".)

The original (poorly phrased) question was:

Is ^$ mean a NULL line?

The OP didn't say where these characters are used. I'll guess they
are used with the pattern match operator.

What does "NULL line" mean?

I assume it means the "empty string" (in which case it cannot be
a "line" since it has no newline character).

So if a boolean response is required then "No" would be the accurate answer.

A more helpful answer would be:

/^$/ matches the empty string, or the 1-char long string where
the 1 char is a newline.
 
T

Tad McClellan

[Please learn the proper way to compose a followup.
Please do this before you make your next followup posting.

Text trimmed and rearranged into a sensible order, like is should
have been in the first place.
]


Tad McClellan wrote:
I don't disagree with your definition Tadd,

s/Tadd/Tad/;


but I'm curious as to what
meaning, other than "at the beginning of the (string | line) match the
end of (string | line)" "^$" might have? Don't meta-characters remain
remain meta-characters where ever they are,


No, they don't.

What the syntax means depends on what language the characters are in.

If you had instead said:

Is /^$/ mean a NULL line?

Then we would have known that the language the metacharacters appear
in is the regex language. (regex language)

But if you had said:

Is [^$] mean a NULL line?

Then the answer would have been: No, it matches any single character
that is not a dollar sign. (character class language)

And if you had said:

Is $vector^$mask mean a NULL line?

Then the answer would have been: No, it is a bitwise exclusive-or
and the sigil of a variable. (Perl language)

Taking just the caret (^) character, it has 3 meanings in 3
different languages:

Perl: bitwise exclusive-or

regex: beginning of string

char class: negates the class


Apart from that, even in the *same* language the same character
can have different meta-meanings. Take curly braces in Perl for
example: part of a hash slice, code block, anonymous hash
constructor, variable name delimiter, part of a hash access...

So, we cannot talk about Perl symbols without knowing a bit about
the context where the symbols appear, hence the encouragement to
post Real Perl Code in the Posting Guidelines.

Have you seen the Posting Guidelines that are posted here frequently?
 
S

smarkham01

Thank you Tadd, I've read your guidlines, many times in fact. Notice
that I never post in your moderated group?

You seem to be back to over-thinking the question. The question didn't
have anything to do with character classes or an XOR! Just two
charactors ^ followed by $.

Sorry life doesn't always flow in the vein you chose.

Please learn the difference between moderator in a moderated group and
ass in a new group before responding.
I don't disagree with your definition Tadd,

s/Tadd/Tad/;


but I'm curious as to what
meaning, other than "at the beginning of the (string | line) match the
end of (string | line)" "^$" might have? Don't meta-characters remain
remain meta-characters where ever they are,


No, they don't.

What the syntax means depends on what language the characters are in.

If you had instead said:

Is /^$/ mean a NULL line?

Then we would have known that the language the metacharacters appear
in is the regex language. (regex language)

But if you had said:

Is [^$] mean a NULL line?

Then the answer would have been: No, it matches any single character
that is not a dollar sign. (character class language)

And if you had said:

Is $vector^$mask mean a NULL line?

Then the answer would have been: No, it is a bitwise exclusive-or
and the sigil of a variable. (Perl language)

Taking just the caret (^) character, it has 3 meanings in 3
different languages:

Perl: bitwise exclusive-or

regex: beginning of string

char class: negates the class


Apart from that, even in the *same* language the same character
can have different meta-meanings. Take curly braces in Perl for
example: part of a hash slice, code block, anonymous hash
constructor, variable name delimiter, part of a hash access...

So, we cannot talk about Perl symbols without knowing a bit about
the context where the symbols appear, hence the encouragement to
post Real Perl Code in the Posting Guidelines.

Have you seen the Posting Guidelines that are posted here frequently?
 
D

David Squire

Thank you Tadd, I've read your guidlines, many times in fact. Notice
that I never post in your moderated group?

You seem to be back to over-thinking the question. The question didn't
have anything to do with character classes or an XOR! Just two
charactors ^ followed by $.

.... but as Tad explained in detail, the question as posed was
unanswerable. Those two characters mean different things in different
contexts. The question gave no information on the context. Tad explained
the various meanings in several contexts.

What exactly do you find unhelpful about that?

DS
 
U

usenet

Please learn the difference between moderator in a moderated group and
ass in a new group before responding.

Wow. New to the group and ALREADY you've insulted (without a bit of
merit) a longtime respected contributor who was trying to be helpful to
you. Do you always find ways to insult helpful people whom you've just
met?

Now, lessee - where's that killfile button? Grrrrrr... darn Google
Groups. Time to hammer on the firewall guys again...
 
J

Jürgen Exner

You seem to be back to over-thinking the question. The question
didn't have anything to do with character classes or an XOR!

Where was that fact mentioned in the original article?
Just two charactors ^ followed by $.

Which is a combination that can have several different meanings, depending
upon in which context they are used. The OP didn't provide any context,
therefore common sense indicates to either say "This question cannot be
answered sensibly because of lack of information" or to list all possible
meanings and let the OP pick whichever is the right one for his problem. I
did the former, Tad did the latter.
Well, take your pick.

jue
 
T

Tad McClellan

Thank you Tadd,


I've asked you nicely to call me by my real name.

Please spell it right, or don't use it.

You seem to be back to over-thinking the question.


You seem to be under-thinking the answer.

The question didn't
have anything to do with character classes or an XOR!


Neither does it have anything to do with regular expressions!

(because you did not show where the characters were used.)

Just two
charactors ^ followed by $.


Exactly so.

We cannot answer your question without knowing which language
the characters were in, and you did not tell us in your OP.

Sorry life doesn't always flow in the vein you chose.


Sorry you cannot compose a coherent question.





[ snip TOFU]
 

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

No members online now.

Forum statistics

Threads
474,197
Messages
2,571,038
Members
47,633
Latest member
BriannaLyk

Latest Threads

Top