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 646039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:34:06+00:00 2026-05-13T21:34:06+00:00

I have two string variables which are both file paths. The code that worked

  • 0

I have two string variables which are both file paths. The code that worked used ereg which is deprecated, so I’m trying to rewrite it using preg_match:

Old code that worked:

$path1 = quotemeta($path);
ereg("$path1(.*)$", $path2, $matches);

Using preg_match which doesn’t seem to work:

$path1 = quotemeta($path);
preg_match("/$path1(.*)$/", $path2, $matches);

It gives

preg_match(): Unknown modifier ‘V’ error.

Also, the main thing I’m trying to obtain is $matches[1], which is the text that matched the first captured parenthesized subpattern, so I’m thinking I can’t really use substr().

  • 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-05-13T21:34:06+00:00Added an answer on May 13, 2026 at 9:34 pm

    If there are some special-characters in your $path variable, those should be escaped — and they should be escaped considering you are using PCRE ; and not POSIX-regex.

    This can be done using the preg_quote function ; which means your code would look like this :

    $path1 = preg_quote($path, '/');
    preg_match("/$path1(.*)$/", $path2, $matches);
    

    In particular, note that PCRE use a delimiter arround the regex — here, you used a / ; this delimiter has to be passed to preg_quote, as this function doesn’t, by default, escape the / character.

    The quotemeta function you were using doesn’t quote all the characters that are used by PCRE.

    As you are porting some code from POSIX-regex to PCRE, you should take a look at the PCRE Patterns section of the manual : PCRE are very powerful, but that power comes with a couple of tricks…

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

Sidebar

Related Questions

I have two Perl string variables containing date values. I want to check whether
I am running an asp.net code-behind that creates a string variable which holds a
I have two properties NSString, both of which I have synthesized and are readonly
I have class implementing Comparator<String> which should sort strings in such manner that strings
I have a function ImageIndexing(type,data) that will return a string according to the two
Basically i have these two pages... each with a string that i get with
I am in a predicament. I have been trying to compare two variables in
I have an two variables as CSV strings. Example: $csva = 1,4,7,10,39,12; $csvb =
I have two String arrays a,b. String a [] = {one,two,three}; String b []
I have two strings String s1=426F62; String s2=457665; The strings are in hex representation.

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.