1

I can't seem to find a function that captures and returns a regex'ed string.

$string = "hello123!";
$string = regexfunction($string, "/([0-9]*)/");
echo $string;

Prints

123

1 Answer 1

4

You want to use preg_match for this, although the syntax will be slightly different:

$string = "hello123!";
preg_match("/[0-9]+/", $string, $matches);
print $matches[0]; // 123
Sign up to request clarification or add additional context in comments.

1 Comment

Oh cool. I should have read the documentation a little more closely. Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.