Forum Moderators: coopster
$string = "a's'd'fas'df'abc'df'_'abc''xyz'abcd'llc";
if (preg_match_all("/('abc')¦('.*?')/", $string, $matches)) {
foreach ($matches[2] as $char) {if ($char) print $char . '<br />';}
}
's'
'fas'
'_'
''
'abcd'
after studying your pattern i get:
preg_replace_callback("/(?:'abc'¦('.*?'))/", 'callback', $string);
may work? going to test..
but i still don't know how to mate a string that doesn't contains specified substring
[^abcdefg] is match only 1 char that isn't one of "abcdefg"
but not for a 'sequence of chars'(string)
Add a modifier after the chars. Eg, to match at least one char or more, [a-zA-Z]+
To match many or none chars that are not alphabetical, [^a-zA-Z]*
[^abcdefg^] excludes the string inside the caretsbcolflesh, are you sure about that? My understanding is that the caret (^) negates the character class, but only if it is the first character. Negating the character class means if any of the individual characters are found, not the exact string. I tested the regex you showed here and did not receive the results expected. Please confirm. Thanks, Coopster.
I'm almost positive that /((abc)+)/ will match at least one occurance of the string "abc", so instead of only getting lines that don't have "abc", only gets lines if the match is empty.
Id est, if you match the substring, replace it with "" or ignore the string totally, but if you don't match it, then use the string.
Would that be an option? Just thinking out loud....
Jordan
$string = "a's'd'fas'df'abc'df";
if (preg_match_all("/'[^a^b^c].*?'/", $string, $matches)) {
print "<pre>"; print_r($matches); print "</pre>";
}
I get the results you originally asked for:
Array
(
[0] => Array
(
[0] => 's'
[1] => 'fas'
)
)
so: $string = "'eabc'a's'd'fas'df'abc'df";
match result is:
Array
(
[0] => Array
(
[0] => 'eabc'
[1] => 's'
[2] => 'fas'
)
)
"'eabc'" contains "abc"
maybe coopster is right: match it, and throw it