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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:46:30+00:00 2026-05-23T14:46:30+00:00

I got some problems with my patterns. Hope somebody could help me with this.

  • 0

I got some problems with my patterns. Hope somebody could help me with this.

given a string

$string = Mutualism has been retrospectively characterised as ideologically situated between individualist and collectivist forms of anarchism.<ref>Avrich, Paul. ''Anarchist Voices: An Oral History of Anarchism in America'', Princeton University Press 1996 ISBN 0-691-04494-5, p.6<br />''Blackwell Encyclopaedia of Political Thought'', Blackwell Publishing 1991 ISBN 0-631-17944-5, p. 11.</ref> Proudhon first characterised his goal as a "third form of society, the synthesis of communism and property."<ref>Pierre-Joseph Proudhon. ''What Is Property?'' Princeton, MA: Benjamin R. Tucker, 1876. p. 281.</ref> Another is <ref name=rupert/>

I want to remove strings inside the &lt;ref&gt; (<ref name='something'></ref> or <ref></ref>) or remove the single ref tag <ref name='sss' />

after replacing the final out put should be :

Mutualism has been retrospectively
characterised as ideologically
situated between individualist and
collectivist forms of anarchism.
Proudhon first characterised his goal
as a “third form of society, the
synthesis of communism and property.”
Another is

my code doesn’t seem to work

$pattern1[] = "/&lt;ref[^\/]*\/&gt;/is"; //remove <ref name=something/>  
$pattern1[] = "/&lt;ref[^\/]*&gt;(.*?)&lt;\/ref&gt;/s";  //remove ref <ref>some text here</ref>
preg_replace($pattern1,"\n", $string);

instead it outputs :

Mutualism has been retrospectively
characterised as ideologically
situated between individualist and
collectivist forms of anarchism.
”Blackwell Encyclopaedia of Political
Thought”, Blackwell Publishing 1991
ISBN 0-631-17944-5, p. 11.</ref>
Proudhon first characterised his goal
as a "third form of society, the
synthesis of communism and
property." Another is

I guess it got caught up with the &lt;br /&gt;

  • 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-23T14:46:31+00:00Added an answer on May 23, 2026 at 2:46 pm

    The Problem is that your first pattern is also matching

    <ref>Avrich, Paul. ”Anarchist
    Voices: An Oral History of Anarchism
    in America”, Princeton University
    Press 1996 ISBN 0-691-04494-5,
    p.6<br />

    [^\/]* matches the following

    >Avrich, Paul. ”Anarchist Voices:
    An Oral History of Anarchism in
    America”, Princeton University Press
    1996 ISBN 0-691-04494-5, p.6<br

    the solution is to use /&lt;ref(?:[^\/&]|&(?!gt;))*\/&gt;/is to match tags

    in this case we use (?:[^\/&]|&(?!gt;))* instead of [^\/]*

    The first (?:[^\/&]|&(?!gt;))* Matches any character excluding / and &, As the first option, or & if its not followed by gt; i.e. not part of a > symbol as the second option here the (?!gt;) is a negative look ahead assertion (see http://www.php.net/manual/en/regexp.reference.assertions.php) this simply means with out consuming the gt;, insure the next 3 character don’t match this pattern.

    The Second simply matches any character that’s not a /.

    so the following code

    $str = "Mutualism has been retrospectively characterised as ideologically situated between individualist and collectivist forms of anarchism.&lt;ref&gt;Avrich, Paul. ''Anarchist Voices: An Oral History of Anarchism in America'', Princeton University Press 1996 ISBN 0-691-04494-5, p.6&lt;br /&gt;''Blackwell Encyclopaedia of Political Thought'', Blackwell Publishing 1991 ISBN 0-631-17944-5, p. 11.&lt;/ref&gt; Proudhon first characterised his goal as a &quot;third form of society, the synthesis of communism and property.&quot;&lt;ref&gt;Pierre-Joseph Proudhon. ''What Is Property?'' Princeton, MA: Benjamin R. Tucker, 1876. p. 281.&lt;/ref&gt; Another is &lt;ref name=rupert/&gt;";
    $match = array(
        "/&lt;ref(?:[^\/&]|&(?!gt;))*\/&gt;/is",
        "/&lt;ref[^\/]*&gt;(.*?)&lt;\/ref&gt;/s",);
    $str = preg_replace($match,'',$str);
    echo $str;
    

    outputs

    Mutualism has been retrospectively
    characterised as ideologically
    situated between individualist and
    collectivist forms of anarchism.
    Proudhon first characterised his goal
    as a “third form of society, the
    synthesis of communism and property.”
    Another is

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

Sidebar

Related Questions

I got some problems with finding a bug in php/mysql application, and I wonder
I got some problems with EOF and stdio in a communication pipeline between a
We've got some problems with an external company trying in integrate into a WCF
I've got some problems on a .NET site where both Latin (åäö) and Latvian
I am just starting with C++ and got some problems in understanding how the
i'm new to java and i got some problems. i'm developping a web application
I'm working on a online game. I got some problems with inserting new data
I've got some problems implementing Conway's Game of Life in JavaScript. At the German
I have tried to ask a variant of this question before. I got some
I have been working on Web application so far and has just got an

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.