Je dispose d'un fichier de texte comme siComment puis-je faire une regex pas 'avaler' un personnage?
{word} definition
{another word} another definition {word} they don't have to be on different lines
Le regex j'utilisais était
$regex = '/\{([a-z]+?)\}(.+?)\{/i';
Ceci, cependant, pose des problèmes en ce qu'elle avale la dernière accolade {, puis il a gagné » t correspond au prochain {dans le mot suivant.
Pour démontrer, je l'ai fait à des fins de débogage
echo preg_replace($regex, '<b style="background-color: red;">$1</b><b style="background-color: yellow;">$2</b>', $content);
Voici un exemple de ma sortie (notez l'accolade d'ouverture dans le mot suivant est pas là, il ne trouve donc pas dans l'expression régulière)
<b style="background-color: red;">shrub</b><b style="background-color: yellow;"> Multi stemmed woody plant</b>Abaxial} side or face away from the axis
Comment puis-je modifier mon regex pour que cela fonctionne? Merci
EDIT
Un grand merci pour vos réponses. J'ai changé mon regex comme si
$regex = '/\{([a-z\-\s]+?)\}([^\{]+)/i';
Je vais aussi regarder dans les articles lookahead.