How to exclude a character from [] using RegEx

I am using PHP preg_match_all, and this is what I can get so far ....

[A-Za-z+\W]+\s[\d]

The only problem is that I need \ W not to be ".

So I tried:

[A-Za-z+[^\dA-Za-z"]\s?]+\s[\d]


[A-Za-z+]\s?+[^A-Za-z\d"]?\s[\d]

by the way, and he just fails, and I really can't understand why.

EDIT:

Here is the whole RegEx;

([A-Z][a-z]+\s){1,5}\s?[^a-zA-Z\d\s:,.\'\"]\s?
[A-Za-z+\W]+\s[\d]{1,2}\s[A-Z][a-z]+\s[\d]{4}

I divided it into two lines, the second line begins with what I published.

Patterns trying to match:

    India – Adulterated Tea Powder Seized 18 April 2011
    India – Importer of Haldiram’s Petha Sweet Cubes Issuing Voluntary Recall 26 April 2011
    India – Undeclared Gluten Found in Sweets by Canadian Authorities 27 April 2011
    India – Adulteration Found in Edible Oils 28 April 2011
    India – Viral Disease Affects Chili Crop in Goa 28 April 2011
NOT ---->   Chili – India: Goa". 8 April 2011
    Ivory Coast – Potential Cocoa Quality Decline despite Sufficient Surplus 11 April 2011
    Japan – Sanuki Kanzume Co. and Failure to Comply with FDA Standards 27 April 2011
    Madagascar – Toxic Sardines 14 April 2011
    Madagascar – Update: Toxic Sardines 26 April 2011
+5
source share
4 answers

The pattern you show matches all letters and characters without words. The only thing that is not included in the template is numbers, and you also should not match a double quote.

[^\d\"_]+\s\d

Edit:

, , , . - , . sting/date, .

<?php
error_reporting(E_ALL);
$str = "    India - Adulterated Tea Powder Seized 18 April 2011
    India - Importer of Haldiram’s Petha Sweet Cubes Issuing Voluntary Recall 26 April 2011
    India - Undeclared Gluten Found in Sweets by Canadian Authorities 27 April 2011
    India - Adulteration Found in Edible Oils 28 April 2011
    India - Viral Disease Affects Chili Crop in Goa 28 April 2011
    Chili - India: Goa\". 8 April 2011
    Ivory Coast - Potential Cocoa Quality Decline despite Sufficient Surplus 11 April 2011
    Japan - Sanuki Kanzume Co. and Failure to Comply with FDA Standards 27 April 2011
    Madagascar - Toxic Sardines 14 April 2011
    Madagascar - Update: Toxic Sardines 26 April 2011";
preg_match_all("/^([^\"]+?)(\d?\d\s[a-z]+\s\d{4})$/im", $str, $m);
echo '<pre>'.print_r($m, true).'</pre>';
?>
+5

, , "( ), [^\"]+ .

0

:

[A-Za-z+\W^\"]+\s[\d]

-1

, - . , :

$str = "India – Adulterated Tea Powder Seized 18 April 2011
    India – Importer of Haldiram’s Petha Sweet Cubes Issuing Voluntary Recall 26 April 2011
    India – Undeclared Gluten Found in Sweets by Canadian Authorities 27 April 2011
    India – Adulteration Found in Edible Oils 28 April 2011
    India – Viral Disease Affects Chili Crop in Goa 28 April 2011
    Chili – India: Goa". 8 April 2011
    Ivory Coast – Potential Cocoa Quality Decline despite Sufficient Surplus 11 April 2011
    Japan – Sanuki Kanzume Co. and Failure to Comply with FDA Standards 27 April 2011
    Madagascar – Toxic Sardines 14 April 2011
    Madagascar – Update: Toxic Sardines 26 April 2011";
if(preg_match_all('~(?:[A-Z][a-z]+\s){1,5}\s?[^a-zA-Z\d\s:,.\'\"]\s?[A-Za-z+\W]+\s[\d]{1,2}\s[A-Z][a-z]+\s[\d]{4}~', $str, $m)) {
   print_r($m[0]);
}

OUTPUT:

Array
(
    [0] => India – Adulterated Tea Powder Seized 18 April 2011
    [1] => India – Undeclared Gluten Found in Sweets by Canadian Authorities 27 April 2011
    [2] => India – Adulteration Found in Edible Oils 28 April 2011
    [3] => India – Viral Disease Affects Chili Crop in Goa 28 April 2011
    [4] => Ivory Coast – Potential Cocoa Quality Decline despite Sufficient Surplus 11 April 2011
    [5] => Japan – Sanuki Kanzume Co. and Failure to Comply with FDA Standards 27 April 2011
    [6] => Madagascar – Toxic Sardines 14 April 2011
    [7] => Madagascar – Update: Toxic Sardines 26 April 2011
)

, Goa" . ?

-1