我正在处理一个要求,我需要在提交表单之前在文本框中允许几个值。下面的正则表达式工作正常,但它允许字符串除了"测试"和" dev"。重要的是它应该忽略区分大小写。它应该允许" dev"," DEV"," dEv"等...
TextView mTxtDisplay;
String url = "http://192.168.1.102/web_service/test.php/";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTxtDisplay = (TextView) findViewById(R.id.tv);
JsonObjectRequest jsObjRequest = new JsonObjectRequest
(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
//parse your responce with JSON object
JSONObject object = new JSONObject(response);
//get JSON object "1" (I'm only doing for 1)
JSONObject jsonObject = jsonArray.getJSONObject("1");
mTxtDisplay.setText("Response: " + jsonObject.getString("name"));
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// TODO Auto-generated method stub
}
});
RequestQueue requestQueue = Volley.newRequestQueue(your_class_context);
requestQueue.add(jsObjRequest);
}
}
答案 0 :(得分:3)
/i
标志可以让你到达目的地:
pattern = text.match(/^(?:testing|dev|)$/i);
text.match(pattern);
Regexr:http://regexr.com/3e6nd
答案 1 :(得分:0)
此代码将返回一个数组,其中第一个匹配数组中的任何单词。请注意,开发或 thetesting 这个词不匹配,因为它使用了词边界断言\b
。
代码:
var userInput = 'Development thetesting devs Dev testING test testIng',
result = userInput.match(/\b(testing|dev)\b/i);
console.log(result && result[0]);