我有一个如下所示的字符串,我想在第二个逗号后提取字符串。提前谢谢。
姓氏,名字,Giberish字符串
答案 0 :(得分:3)
不要使用复杂的REGEX,只需使用 return (
<section className="">
<h2 className="title has-text-centered">Heres what we recommend in London</h2>
<div className="columns is-multiline">
{places.map((place, i) => <div className="column is-one-quarter" key={i}>
<ul>
<li>
<div className="card-image">
<figure className="image">
<h2 className="has-text-centered has-text-grey">Venue: {place.venue.name}</h2>
<h2 className="has-text-centered has-text-grey">Category: {place.venue.categories[0].pluralName}</h2>
<h2 className="has-text-centered has-text-grey">Why?: {place.reasons.items[0].summary}</h2>
<p className="has-text-centered has-text-link">Address: {place.venue.location.formattedAddress}</p>
<p className="has-text-centered has-text-link">ID: {place.venue.id}</p>
{/* <img className="animated rotateIn" src={place.venue.categories[0].icon.prefix.concat(place.venue.categories[0].icon.suffix)}/> */}
</figure>
</div>
</li>
</ul>
</div>)}
</div>
</section>
);
};
。
explode()
请参阅操作:https://3v4l.org/16ABc
答案 1 :(得分:0)
你可以使用CSV解析器,然后在第二个索引(这将是第二个逗号)之后迭代数组中的所有值:
$return = '';
$string = 'Last Name, First Name, Giberish String';
$values = str_getcsv($string);
foreach($values as $key => $value){
if($key >= 2) {
$return .= trim($value);
}
}
或者可以使用正则表达式:
$return = '';
$string = 'Last Name, First Name, Giberish String';
preg_match('/^(?:.*?,){2}\s*\K.*/', $string, $match);
$return = $match[0];