• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 220
  • Last Modified:

regular expressions

$var = string101;
$var = string1012;
$var = string10123;

hi how can i use regular expression to retrieve only the numbers from this variable in php
1 Solution
RobOwner (Aidellio)Commented:
use preg_match

$var1 = string101;
$var2 = string1012;
$var3 = string10123;

$pattern = '/[0-9]+/';
preg_match($pattern, $var1, $matches);

$num1 = $matches[0];


this would have $num1 = 101;

you could repeat for the others
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now