正則化提取特定字符串中間的內容

1、JS代碼:

var field_regex=/(涉及).+(領域)/;
var method_regex=/(涉及一種).+(方法)/;
field_match=tech_field_str.match(field_regex);
if(field_match!=null)
{
	field_result=field_match[0].replace(field_match[1],"");
    field_result=field_result.replace(field_match[2],"");
	method_match=tech_field_str.replace(field_match[0],"").match(method_regex);
     if(method_match!=null)
     {
         method_result=method_match[0].replace(method_match[1],"");
         method_result=method_result.replace(method_match[2],"");
         patent_array.push([method_result,field_result,company_name]);
     }
}

2、PHP代碼:

$field_regex='/涉及(.*?)領域/';
$method_regex='/涉及一種(.*?)方法/';
foreach ($chosen_patent as $data)   //獲得patent_array
{
	preg_match($method_regex, $data[0], $method_matches);
    preg_match($field_regex, $data[0], $field_matches);
    if(count($method_matches)>=1 and count($field_matches)>=1)
    {
    	array_push($mylist,$method_matches[1],$field_matches[1],$data[1]);
    	array_push($patent_array,$mylist);
        $mylist=$this->my_pop($mylist,3);
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章