Q: PRCE: substring exclusion in capturing group result This is some kind of academic question, I just wondering if it is possible to capture a group (f.e. with usage of PHP preg_match() function) with substring excluded in result. I'm interested in achieving this on regex level. Let me explain, what I'm talking about.
F.e., I have source string like:
...   
... needed_NUMERIC_substr_1 not_needed_ALPHA_substr need_NUMERIC_substr2 ...  
...

Is it possible to write regexp which will return:
Array
(
    [0] => %**NOT_IMPORTANT_THAT_WILL_BE_HERE**%
    [1] => needed_NUMERIC_substr_1 need_NUMERIC_substr2
)

I understand, that it is possible to match both needed strings separately with different capturing groups and then to perform any required action in the code. This is just academic interest.
I thought about using conditional subpatterns or lookahead and lookbehind zero-width assertions, but wasn't able to found solution. If it is possible, how it could be achieved?

A: No it's not possible.
preg_match doesn't provide any options how to join matched groups together or erase (replace with empty string) part of matched text.

A: Since the question really seems to be how to get 123456 from the input string 123abc456, I wouldn't use preg_match. Instead I would use preg_replace and replace everything that is not a digit with the empty string, so they effectively get removed.
$string = '123abc456';
$result = preg_replace('/[^0-9]/', '', $string);
echo $result; // prints 123456


A: Not possible. Capturing groups capture only continues substrings of the input string (or nothing at all).
