Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

176
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!