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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:42:53+00:00 2026-05-23T10:42:53+00:00

I have googled for a regex to grab and also read a few tutorials

  • 0

I have googled for a regex to grab and also read a few tutorials and I can’t seem to get a solid regular expression to do this.

What I need to do is write a JavaScript regular expression that will match PHP tags within a string.

I have inherited a large php project where the views that have mixed html and php are not very readable. So what I’m doing is writing an IDE extension for my own personal use to strip out php that is mixed in a php view in order to run an HTML indentation script on it without confusing the HTML indentation script. Then after the indentation script has finished I go back and re-insert the php again.

What I have so far is this (I converted this from a regex that looks for brackets [], I knew it wouldn’t match everything but it got me far enough to flesh out my IDE extension):

var php_tag_pattern = /<\?[^<>]*\?>/;

Now for obvious reasons it is not matching on code like this:

<?=$common->format_number($acct_info['number'])?>

or this:

<?
$wifi = $wifi_lib->wifi_radius($v['radiusgroupname']);
if (!empty($wifi)) :?>

I have been messing around with this for the last several hours so I thought I would finally ask for help to see what I’m missing.

Thanks!

  • 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-23T10:42:53+00:00Added an answer on May 23, 2026 at 10:42 am

    To match multi-line php text you will need an implementation of DOTALL in Javascript. Unfortunately Javascript doesn’t have s flag but there is a workaround. Try this code:

    var php_tag_pattern = /<\?[=|php]?[\s\S]*?\?>/;
    

    [\s\S] will make sure to match php text in multi line including new lines as well.

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

Sidebar

Related Questions

I have read the Google python regex tutorial about regular expression and tried to
i have googled in the last 3 hours but i can't seem to find
I have Googled it, and found the following results: http://icfun.blogspot.com/2008/03/regular-expression-to-handle-negative.html http://regexlib.com/DisplayPatterns.aspx?cattabindex=2&categoryId=3 With some (very
I have googled this a little and didn't really find the answer I needed.
I'm at wits end now, I have googled this to death and found nothing.
I am new to Emacs. I have googled this but no good answer there.
I am sure I am just missing something. But I have googled this for
I have a question about regex/Python. Sorry if this topic has been discussed millions
Before asking this question I have Googled for this problem and I have looked
I'm getting this error even though I have declared my regex variable. my $pattern

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.