-1

how to remove subscript or superscript from below text?

Here [5][6] are in superscript.

The Bhagavad Gita presents a synthesis[5][6] of Hindu ideas about dharma,[5][6][7] theistic bhakti,[8][7] and the yogic paths to moksha.[6] The synthesis presents four paths to spirituality.

is there any way to find it?

sanjaya
  • 204
  • 2
  • 4
  • 11
  • 3
    SO is not meant to be a code writing service. Show us what you've tried. Read the guide on [how to ask a good question](https://stackoverflow.com/help/how-to-ask). – Don't Panic Feb 23 '19 at 03:31
  • Can you clarify your question? do you want to find and replace superscript characters with blanks? (you could accidentally remove text that is intended if you create a function like this?). Also, is the php tag necessary? – Rachel Gallen Feb 23 '19 at 03:32
  • Possible duplicate of [Replace superscript and subscript chars from a string Javascript](https://stackoverflow.com/questions/45163036/replace-superscript-and-subscript-chars-from-a-string-javascript) – Aniket G Feb 23 '19 at 03:33
  • yes i want to find and replace superscript characters with blanks – sanjaya Feb 23 '19 at 04:03

1 Answers1

0
<?php
    // regex breakdown
    // \[  matches the left bracket
    // .   any character except line breaks
    // *   0 or more of the preceding character
    // ?   lazy matching
    // \]  matches the right bracket
    $pattern = '/\[.*?\]/';
    $replacement = '';
    $subject = "The Bhagavad Gita presents a synthesis[5][6] of Hindu ideas about dharma,[5][6][7] theistic bhakti,[8][7] and the yogic paths to moksha.[6] The synthesis presents four paths to spirituality.";
    $limit = -1;
    $count = 0;
    $result = preg_replace ($pattern, $replacement, $subject, $limit, $count);
?>

Should return

The Bhagavad Gita presents a synthesis of Hindu ideas about dharma, theistic bhakti, and the yogic paths to moksha. The synthesis presents four paths to spirituality.

beenhere4hours
  • 970
  • 9
  • 12