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

  • SEARCH
  • Home
  • 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 8387771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:18:19+00:00 2026-06-09T18:18:19+00:00

$ is not matching a position immediately before a newline that is the last

  • 0

$ is not matching a position immediately before a newline that is the last character.

Ideally /1…$/ should match but match happens with the pattern /1….$/ which seems to be wrong.

What could be the reason?

PHP doc also says A dollar character ($) is an assertion which is TRUE only if the current matching point is at the end of the subject string, or immediately before a newline character that is the last character in the string (by default).

$subject = 'abc#
123#
';
$pattern = '/1...$/';
preg_match_all($pattern,$subject,$matches); // no match

Update:
I suspect extra dot due to \r\n format of newline.
I did following experiment and see some hint.

$pattern = '/1...(.)$/';

echo bin2hex($matches[1]); // 28

28 seems to be equal to \r (CR) so basically $ is matching before \n not before \r\n, that may be the reason of my problem.

enter image description here

Image after non printable character turn on

  • 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-09T18:18:21+00:00Added an answer on June 9, 2026 at 6:18 pm

    Issue was due to different newline representation of window file and linux file

    Why this issue:

    • I created php file in window and transferred to linux where PHP was installed.
    • Windows uses \r\n to represent newline and linux \n ==> that’s why initially it was taking extra dot to match.

    Below experiment confirmed the same:

    $subject = 'abc#
    123#
    ';
    $pattern = '/1...(.)$/';
    preg_match_all($pattern,$subject,$matches);
    echo bin2hex($matches[1]); // 28 
    // 28 is equivalent of \r or CR(carriage return)
    

    Created new file in linux system and /1…$/ catches the match 🙂

    I hope this will save someone’s time if stuck with same problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do I match all lines not matching a particular pattern using grep ?
I'm developing a game for iOS that should include the multiplayer. It's not a
I am having problems downloading files possibly due to the file extensions not matching
Eclipse does not highlight matching variables for me: I've already tried to change Mark
Not ever sure if it can be done, but is it possible to use
Not to sound like a koan, but just wondering if there are definite rules
Not sure if im just being stupid or something but here goes i work
Ok, I'm trying to make a program that finds the position of a colored
This is a bit of a weird desire but I am making a matching
The issue is the results from local host are not matching up with the

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.