Can anyone please let me know how to seperate Model Numbers from a string

ForEx Titles:
1) Sony DCSW380B 14MP Camera
2) Casio 10MP Camera EX-Z3/3
3) Panasonic Lumix Camera DMC-G1 12MP

Output would be:
For 1) "DCSW380B 14MP" OR ""DCSW380B"
For 2) "10MP EX-Z3/3" OR "EX-Z3/3"
For 3) "DMC-G1 12MP" OR "DMC-G1"

Criteria:
1) All letters of model number are CAPITAL
2) It may include alphabets, numbers or special symbol like "/", "-"
3) Model numbers can be anywhere in the title (not a specific position like 2nd in array on explode)

Not sure if i need to use preg_match fuction.

Please assist. Thanks in advance

Dani AI

Generated

Nice, the thread already shows the right direction: use pattern-based matching to pull out tokens that "look like" model IDs. called out the core idea (match contiguous tokens made of uppercase letters, digits and a few separators) and confirmed it with a working script. That covers a large percentage of product titles quickly, but it is not a perfect, one-size-fits-all solution.

There are important edge cases to watch for, as noted. Brands may contain digits (for example "O2"), model names can include lowercase letters or words ("Mark", "i"), specs like "12MP" or "8GB" are often adjacent but are not the model, and some models are multi-word. Pure pattern matching can produce false positives or miss mixed-case models.

A practical workflow to improve accuracy:

  1. Normalize the title (trim, collapse whitespace, remove enclosing punctuation).
  2. Tokenize on spaces and common punctuation.
  3. For each token compute simple features: containsDigit, containsLetter, uppercaseRatio, length, containsSeparator (-,/,+), and whether it appears in a stoplist of generic words (Camera, Digital, MP, GB, etc.).
  4. Score tokens (give points for digits, separators, high uppercase ratio; subtract for stoplist membership).
  5. Merge adjacent high-scoring tokens (to capture multi-token models and attach spec suffixes).
  6. Fall back to a brand->model lookup or manual review for low-confidence cases.

Tune thresholds against a sample of real titles and keep a stoplist and a small whitelist of known brands/models for best results. For implementation details and functions you can use in PHP, see the preg_match_all documentation: preg_match_all.

Recommended Answers

All 3 Replies

You would need to concat the matches of:

(\b[A-Z0-9/-]*\b)

Are you sure that model numbers are ALWAYS contain at least a number? Or the brand NEVER contain a number? I think you can't just assume that all product will meet this criteria. For instance, "O2 X2i".
It will be even harder since the position of product number is arbitrary.

I think this is human's job

I got the solution.
Here it is:

<?php
$titles = Array('Sony DCSW380B 14MP Camera', 'Casio 10MP Camera EX-Z3/3', 'Panasonic Lumix Camera DMC-G1 12MP');

foreach($titles as $item)
{
    if(preg_match_all('/\b([A-Z0-9\/\-\+]+)\b/', $item, $tmp))
        print implode('||', $tmp[1]).'<br />';
}

?>

Output is separated by "||" in case i need this in future.
Anyway, Thanks in bunch guys for you kind help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.