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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:12:37+00:00 2026-06-03T09:12:37+00:00

In brief Given a string like this – MAX_checkTime_Hour(‘0,1’, ‘=~’) and (MAX_checkTime_Day(‘1,2’, ‘=~’) or

  • 0

In brief
Given a string like this –

MAX_checkTime_Hour('0,1', '=~') and (MAX_checkTime_Day('1,2', '=~') or MAX_checkTime_Day('1,2', '=~')) and MAX_checkGeo_Country('DZ,AO,BJ)

I want to insert <br /> tags before and in between patterns like and MAX_ or and (MAX_ or and ((MAX_ and so on, so that the output is –

MAX_checkTime_Hour('0,1', '=~')<br /> and <br />(MAX_checkTime_Day('1,2', '=~') or MAX_checkTime_Day('1,2', '=~'))<br /> and <br />MAX_checkGeo_Country('DZ,AO,BJ)

What I have done so far
With the following regex replacement I am almost there. The insertion of <br /> tags is working but I am having to insert a fixed number of &nbsp;s –

preg_replace("/\s+and\s+MAX_/",'<br />&nbsp;&nbsp;&nbsp;and&nbsp;&nbsp;&nbsp;<br />MAX_',$str);

I wanted to –

  • preserve the exact number of whitespaces.
  • preserve the exact number of first brackets before MAX_.

So, if the original string was like this –

MAX_checkTime_Hour('0,1', '=~') <3 white spaces here> and <5 white spaces here> #2 first brackets here#MAX_checkTime_Day('1,2', '=~')

I would like the output to be –

MAX_checkTime_Hour('0,1', '=~')<br /> <3 white spaces here> and <5 white spaces here> <br /><first brackets here>MAX_checkTime_Day('1,2', '=~')

Update
I tried with the following assuming that the variable number of whitespaces would be stored in variables, but it did not work –

preg_replace("/{\s+}and{\s+}MAX_/",'<br />$1and$2<br />MAX_',$str);
  • 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-03T09:12:38+00:00Added an answer on June 3, 2026 at 9:12 am

    I suppose you forgot about ‘or’ operator in the source (located right before third MAX_). There is alt. version of regexp – it’s more generic (because it can match and safely replace both ‘and’ & ‘or’ operators) and it has been little more optimized (because it doesn’t use look-ahead/look-behind syntax):

    $result = preg_replace('/(\s+(and|or)\s+)(\(*MAX_)/', '<br/>$1<br/>$2', $str);
    

    Also it DRY compatible, replacement string doesn’t contains any parts of the source string

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

Sidebar

Related Questions

Im a clojure beginner.I did the following steps as given on http://www.unexpected-vortices.com/clojure/brief-beginners-guide/development-env.html to setup
I'll keep this brief. I am trying to keep a map between strings and
I know this might sound like something which is explained everywhere.. but I've been
I think this is not an easy question. I'll be brief and give a
Imagine you've been given two System.Type's and you want to determine if there is
I have a lot of strings like this to find and replace in visual
I have a method declared like so: /*! \brief Removes the leading and trailing
Brief: This is a past exam question from a Miranda exam but the syntax
could someone give me a brief explanation of what is happening differently in the
Brief question What command can I use to make my DataSet refresh it's connection

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.