正则表达式,匹配两个char之间的char

时间:2016-04-18 14:23:35

标签: regex

我对正则表达式有一些问题。

文字:

alpha,beta,charlie,"delta delta,delta,",echo

必填项:

如果,位于双引号" "内,我想用空格替换alpha,beta,charlie,"delta delta delta ",echo

".*,.*"

我尝试了,,但它匹配双引号内的所有文字而不仅仅是public class FonteTabelaExercicios : UITableViewSource { private ExercicioBanco banco = new ExercicioBanco (); private List<Exercicio> exercicosBanco; private string cellIdentifier = "TableCell"; UIButton btn; private NavController nav = new NavController (); public FonteTabelaExercicios (List<Exercicio> banco) { exercicosBanco = banco; } public override nint RowsInSection (UITableView tableview, nint section) { if (exercicosBanco != null) { return exercicosBanco.Count; } else { return 0; } } public override UITableViewCell GetCell (UITableView tableView, Foundation.NSIndexPath indexPath) { UITableViewCell cell = tableView.DequeueReusableCell (cellIdentifier); if (cell == null) cell = new UITableViewCell (UITableViewCellStyle.Default, cellIdentifier); cell.TextLabel.Text = exercicosBanco [indexPath.Row].Nome + " - " + exercicosBanco [indexPath.Row].Quantidade; btn = new UIButton (new CGRect (0, 0, 70, 30)); btn.SetTitle("Apagar", UIControlState.Normal); btn.SetTitleColor (UIColor.White,UIControlState.Normal); btn.BackgroundColor = UIColor.Blue; cell.AccessoryView = btn; btn.TouchUpInside += (sender, e) => { int result = 0; UIAlertView alert = new UIAlertView( "Confirmação", "Deseja apagar este dado?", null, NSBundle.MainBundle.LocalizedString ("Cancelar", "Cancel"), NSBundle.MainBundle.LocalizedString ("OK", "OK") ); alert.Show (); alert.Clicked += (object sender2, UIButtonEventArgs es) => { if (es.ButtonIndex == 0 ) { Console.WriteLine("Não"); } else { result = banco.ExecutaDelete(exercicosBanco [indexPath.Row]); if (result > 0) { //Loads listaRecorsViewController with uitableview listaRecorsViewController record = (listaRecorsViewController)nav.Storyboard.InstantiateViewController("listaRecords"); nav.PushViewController(record, false); } } }; }; return cell; } }

有人可以帮忙吗?

2 个答案:

答案 0 :(得分:0)

您要求的单个正则表达式很难(或不可能)。

我建议首先通过像"[^"]*"这样的正则表达式匹配引号内的所有内容,然后简单地用编程语言迭代匹配的输出,用空格替换所有逗号。

答案 1 :(得分:0)

试试这个gnu解决方案:

gawk -F \" -v OFS=\" '{
 for (i=2;i<=NF;i+=2) {
    gsub(/,/," ",$i);
 }
 print;
}'

测试:

 printf "alpha,beta,charlie,\"delta delta,delta,\",echo\n" | gawk -F \" -v OFS=\" '{
 for (i=2;i<=NF;i+=2) {
    gsub(/,/," ",$i);
 }
 print;
}'
alpha,beta,charlie,"delta delta delta ",echo