right test seems working avoiding characters don't want it's returning count of 2. know why, don't know how address it. problem last ? being excluded because actual match 2nd match (?+
it's not matching 3rd since there no "starting" character pattern, ?)
.
$pattern = "/([^\w\d'\"`]\?[^\w\d'\"`])/"; $subject = "`test` = ? , `other` = (?+?)"; $count = preg_match_all($pattern, $subject, $matches); echo "count: $count\n"; // echoes 2 instead of 3
basically, want count parameters used, match ?
in $subject
?
not surrounded letters, numbers, quotes, , ticks.
this actual pattern matters:
[^\w\d'\"'`]
update: others, miken32's solution convert above pattern to:
(?=[^\w\d'\"'`])
try using lookahead assertion:
$pattern = "/((?<=[^\w\d'\"`])\?(?=[^\w\d'\"`]))/";
it ahead without moving search forward.
edited add lookbehind assertion well.
Comments
Post a Comment