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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:19:28+00:00 2026-06-13T00:19:28+00:00

Is this a correct syntax for preg_replace (regular expression) to remove ?ajax=true or &ajax=true

  • 0

Is this a correct syntax for preg_replace (regular expression) to remove ?ajax=true or &ajax=true from a string?

echo preg_replace('/(\?|&)ajax=true/', '', $string);

So for example /hello/hi?ajax=true will give me /hello/hi and /hello/hi?ajax=true will give me /hello/hi

Do I need to escape &?

  • 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-13T00:19:29+00:00Added an answer on June 13, 2026 at 12:19 am

    Why don’t you try it?

    You don’t need to escape “&”. It is not a special character in regex.

    Your expression should be working, that is an alternation that you are using. But if you have only single characters in your alternation, it is more readable, if you use a character class.

    echo preg_replace('/[?&]ajax=true/', '', $string);
    

    [?&] is a character class, it will match one character out of the characters listed between the square brackets.

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

Sidebar

Related Questions

What is the correct syntax for this: IList<string> names = Tom,Scott,Bob.Split(',').ToList<string>().Reverse(); What am I
Is this the correct jQuery syntax for checking if the div is hidden &&
please, is this the correct syntax for copying a particular row from one table
what's the correct syntax in subtracting a field value from a variable value? Example:
According to Wikipedia this syntax looks correct... INSERT INTO dbo.metadata_type (name, publishable) VALUES (Content
I can't get the JOIN syntax correct to alter this existing MySQL query in
In PHP, filter_var('www.example.com', FILTER_VALIDATE_URL) returns false . Is this correct? Isn't www.example.com a valid
Is this Regex correct if I have to match a string which is atleast
Is this the correct syntax for passing a file pointer by reference? Function call:
What is the correct syntax for this code: is it: printf(printf(\\%d\,%s);, some_var); or printf(printf(\%%d\,%s);,

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.