单引号或双引号分隔符的正则表达式 [英] Regex for single or double-quote delimeter

查看:63
本文介绍了单引号或双引号分隔符的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个正则表达式,用于通过双引号拆分字符串:

I have wrote a regex for split a strings by double-qoutes:

Pattern delimeter = Pattern.compile("\"");

我如何扩展它以同时使用单引号和双引号?

How could I extend it for working with BOTH single and double qoutes?

我已经尝试过:

   Pattern delimeter = Pattern.compile("\"'");

但这行不通

推荐答案

两种方法:

 Pattern delimeter = Pattern.compile("[\"']"); //Enclose them in brackets
 Pattern delimeter = Pattern.compile("\"|'"); //But a "OR" between them.

这篇关于单引号或双引号分隔符的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆