Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7825819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T09:09:53+00:00 2026-06-02T09:09:53+00:00

In a Perl SO answer , a poster used this code to match empty

  • 0

In a Perl SO answer, a poster used this code to match empty strings:

$userword =~ /^$/; #start of string, followed immediately by end of string

To which brian d foy commented:

You can’t really say that because that will match one particular non-empty string.

Question: Which non-empty string is matched by this? Is it a string consisting of “\r” only?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T09:09:54+00:00Added an answer on June 2, 2026 at 9:09 am

    Let’s check the docs, why don’t we? Quote perlre,

    $: Match the end of the line (or before newline at the end)

    Given

    \z: Match only at end of string

    That means /^$/ is equivalent to /^\n?\z/.

    $ perl -E'$_ = "";    say /^$/ ||0, /^\n?\z/ ||0, /^\z/ ||0;'
    111
    
    $ perl -E'$_ = "\n";  say /^$/ ||0, /^\n?\z/ ||0, /^\z/ ||0;'
    110
    

    Note that /m changes what ^ and $ match. Under /m, ^ matches at the start of any “line”, and $ matches before any newline and at the end of the string.

    $ perl -E'$_ = "abc\ndef\n";  say "matched at $-[0]" while  /^/g'
    matched at 0
    
    $ perl -E'$_ = "abc\ndef\n";  say "matched at $-[0]" while  /$/g'
    matched at 7
    matched at 8
    

    And using /m:

    $ perl -E'$_ = "abc\ndef\n";  say "matched at $-[0]" while  /^/mg'
    matched at 0
    matched at 4   <-- new
    
    $ perl -E'$_ = "abc\ndef\n";  say "matched at $-[0]" while  /$/mg'
    matched at 3   <-- new
    matched at 7
    matched at 8
    

    \A, \Z and \z aren’ t affected by /m:

    $ perl -E'$_ = "abc\ndef\n";  say "matched at $-[0]" while  /\A/g'
    matched at 0
    
    $ perl -E'$_ = "abc\ndef\n";  say "matched at $-[0]" while  /\z/g'
    matched at 8
    
    $ perl -E'$_ = "abc\ndef\n";  say "matched at $-[0]" while  /\Z/g'
    matched at 7
    matched at 8
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Based upon SO answer my ($export = $doc) =~ s{.odt}{.pdf}; why does this Perl
Alright, I'm still a newbie in Perl, so the answer to this question may
Obviously this applies equally with python, bash, sh, etc substituted for perl! Quentin's answer
Hi guys i have this line of code in a perl script where i
Perl is really good for writing the kind of string/file parsing programs that I
In Perl, there is an ability to break an outer cycle like this: AAA:
Seems like in Perl this should be easy or a module, but I have
In Perl, working with a paragraph of text in one big long string with
I found this Perl script while migrating my SQLite database to mysql I was
How do I compare two strings in Perl? I am learning Perl, I had

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.