我正在为PHP中的preg_replace寻找一个RegEx,用于以下场景:
"Bjerre- Jonas, Jorgensen- Silas, Wohlert- Johan, Madsen- Bo"
"Jonas Bjerre, Silas Jorgensen, Johan Wohlert, Bo Madsen"
-
匹配我是PHP和RegEx的菜鸟,并且在preg_replace("/^\"(?<=- )/", ""$2 $1$3"", $input_lines);
之类的东西中玩过public class MainActivity extends ActionBarActivity {
Toolbar toolbar;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toolbar = (Toolbar) findViewById(R.id.app_toolbar);
setSupportActionBar(toolbar);
Profile profile = (Profile) getSupportFragmentManager().findFragmentById(R.id.profileFragmentInMain);
profile.setUp((DrawerLayout) findViewById(R.id.drawer),toolbar);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
}
,结果很糟糕。谢谢你的帮助!
答案 0 :(得分:1)
([^," -]*)\s*-\s*([^," ]*)
试试这个。看看演示。
http://regex101.com/r/hI0qP0/20
$re = "/([^\", -]*)\\s*-\\s*([^,\" ]*)/m";
$str = "\"Bjerre- Jonas, Jorgensen- Silas, Wohlert- Johan, Madsen- Bo\"";
$subst = "$2 $1";
$result = preg_replace($re, $subst, $str);