Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

179
Vistas
Regular expression to search word in text and not as part of a string (preg_match_all)

I hope anyone can help me with this question.

What I'm looking for is to search a string for a word

$text = 'is Apple, name testintapple test APPLE name test';
preg_match_all('/apple/i', $text, $output_array);

Return

array(
0   =>  Apple
1   =>  apple
2   =>  APPLE
)

I would like this to just return:

array(
0   =>  Apple
1   =>  APPLE
)
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

What you need is:

preg_match_all('/\bapple\b/i', $text, $output_array);

The \b is a word boundary. So it will only match if apple is used as a word an not a part of a bigger string.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda