regex - everthing between quotes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ab

    regex - everthing between quotes

    Hi,

    I'm trying to get a preg_replace to replace wihhin a large string
    variable, only words that are NOT preceded by a " or a >. For
    instance, in:


    While this sentence <em>does</em> serve as a useful example, it is
    otherwise uninteresting, and does stand much of a chance, however
    "useful" it might be, of publication.

    I want the expression to replace the does that is not in em tags, and
    the useful that is not in quotes.

    Any assitance would be great.
  • Janwillem Borleffs

    #2
    Re: regex - everthing between quotes

    ab wrote:[color=blue]
    > I want the expression to replace the does that is not in em tags, and
    > the useful that is not in quotes.
    >[/color]

    $sentence = preg_replace(
    array(
    '#(?<!")useful( ?!")#',
    '#(?<!<em>)does (?!</em>)#'
    ),
    "",
    $sentence
    );


    JW



    Comment

    Working...