2016-04-25 45 views

回答

0

因爲沒有使用正則表達式,你可以嘗試

trim(strstr($text, '-'),'-'); 
0

沒有正則表達式的需要:

$result = substr($text, strpos($text, '-')+1); 

或者:

$result = trim(strstr($text, '-'), '-'); 
0

這將工作

[^-]*- 

Regex Demo

PHP代碼

$re = "/[^-]*-/"; 
$text = "1235-text1-text2-a1-780-c-text3"; 
$result = preg_replace($re, "", $text, 1); 

Ideone Demo

0

或者使用的preg_match

<?php 
$text = "1235-text1-text2-a1-780-c-text3"; 

preg_match("%[^-]*-(.*)%",$text, $matchs); 
var_dump($matchs[1]); 
// Output "text1-text2-a1-780-c-text3" 
?> 
0

當你想使用的preg_replace:

$re = '/^([\w]*-)/'; 
$str = "1235-text1-text2-a1-780-c-text3"; 
$match = preg_replace($re, "", $str); 
var_dump($match); 

另一種使用的preg_match:

$re = '/-(.*)/'; 
$str = "1235-text1-text2-a1-780-c-text3"; 
preg_match($re,$str,$matches); 

var_dump($matches[1]); 
相關問題