kevin
kevin

Reputation:

What does the regular expression $$ mean?

what does the regular expression $$ evaluate to?

Upvotes: 3

Views: 3238

Answers (6)

pts
pts

Reputation: 87291

It depends on the programming language and regexp engine.

  • In Perl, /$$/ matches the PID (process id) of the current process (see more in dsm's answer).
  • In Ruby, both /$$/ and /$/ match the empty string before the first newline, or the end of the string if there are no newlines in the string.
  • In Python, both re.search('$$', s) and re.search('$', s) match the empty string before the last newline, or the end of the string if there are no newlines in the string.
  • (Other languages or regexp engines may behave differently.)

Please note that the flags (usually the s and the m flags) associated with the regexp affect what $ matches. The items above use the default flags.

Upvotes: 2

dsm
dsm

Reputation: 10395

in Perl, embedding $$ into a regular expression will result in the PID of the perl process being inserted

# Suppose perl has a PID of 5432
my $str1 = "some";
my $str2 = "5432";

print "1 match: $str1" if $str1 =~ /^$$/;
print "2 match: $str2" if $str2 =~ /^$$/;

Output:

2 match: 5432

Inserting a single $ will match the end of line.

Upvotes: 3

Chas. Owens
Chas. Owens

Reputation: 64929

That construct is unlikely to occur except in languages that allow variable interpolation in the regex. In that case it most likely will match the process id of the current process (since $$ is generally a variable that holds the process id).

Upvotes: 2

Luixv
Luixv

Reputation: 8710

Normally is a matcher for end-of-line but this depend on which language are you using. Without this specific information is difficult to answer.

BTW, in csh means the process number. It is not a regular expression.

Luis

Upvotes: -1

M. Jahedbozorgan
M. Jahedbozorgan

Reputation: 7054

It depends on the underlying regex engine. But in the .Net framework System.Text.RegularExpressions.Regex class, $ within regular expressions specifies that the match must occur at the end of the string, before \n at the end of the string, or at the end of the line, so $$ will match everything!

($$ has another meaning in replacement patterns, which substitutes a single "$" literal.)

Upvotes: 1

soulmerge
soulmerge

Reputation: 75724

It just depends on the underlying regex engine. In vim it would match a dollar sign at the end of line, for example. I'd guess that Posix would require the engine to match the same as '$' since that literal has 0 length as Tomalak pointed out.

Upvotes: 2

Related Questions