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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:39:42+00:00 2026-06-03T20:39:42+00:00

I wrote a simple regex-script in PHP: <?php $string = \section{Test 1} sdfgsdfg; $regex

  • 0

I wrote a simple regex-script in PHP:

<?php  
$string = "\section{Test 1} 
sdfgsdfg";  
$regex = "@\\section{(.*?)}@U";  
$replace = "$1jksdfahlkjh";  
$newString = preg_replace ($regex, $replace, $string, -1 );  
?> 

See: http://regexp-tester.mediacix.de/t287

using

echo $newString;

only give me

\section{Test 1} sdfgsdfg

Regex-patterns like

$bbcode = array(

"/\[b\](.*?)\[\/b\]/is" => "<strong>$1</strong>",
"/\[u\](.*?)\[\/u\]/is" => "<u>$1</u>",
"/\[url\=(.*?)\](.*?)\[\/b\]/is" => "<a href='$1'>$2</a>"

);
$text = "[b]Text[/b][u]Text[/u]";

$text = preg_replace(array_keys($bbcode), array_values($bbcode), $text);
echo $text;

works great. Is there any solution? I don’t want to write an whole LaTeX-Parser, but I want to replace those “\section{…}”-Strings

  • 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-03T20:39:43+00:00Added an answer on June 3, 2026 at 8:39 pm

    You need to escape the \‘s, because otherwise they will already be treated as an escape by php itself and then stripped:

    $regexp = "@\\\\section{(.*)}@";
    

    The U modifier is unnecessary, as that makes the .*? greedy again, so you are reversing the reversing. Just .* works just as well.

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

Sidebar

Related Questions

i wrote a simple function in controller public string LinkProjectSquareFilter(int squareId) { return squareId.ToString();
I'm trying to write a (I think) pretty simple RegEx with PHP but it's
I wrote this regex with the idea that it will match any string in
I coded a relatively simple script using python and also wrote doc strings for
I wrote a simple script, using VBA. (I need to optimize some work with
I wrote a pretty simple preg_match_all file in PHP: $fileName = 'A_DATED_FILE_091410.txt'; $matches =
I am trying to write a simple regex to match a percentage value range
I wrote simple load testing tool for testing performance of Java modules. One problem
I wrote a simple javascript function to display a progressbar with the help of
I wrote a simple CMS for one of my clients which does specifically what

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.