Please help me out what expression i use in if condition to check whether the value of id is in digit or alphabet and i m using phonegap to develop a android app
In XML:-
<cat>
<id>1</id>
</cat>
<cat>
<id>30</id>
</cat>
<cat>
<id>ATTR11</id>
</cat>
<cat>
<id>ATR2</id>
</cat>
In JQuery
$.ajax({
type: "GET",
url: "one.html",
contentType: "text/xml",
dataType: "xml",
data: "",
success: function(xml){
$(xml).find("cat").each(function () {
var id = $(this).find('id').text();
if(id == ??????){
var a2 = ''+id+'';
$("#xyz").append(a2).trigger('create');
}else{
var a1 = ''+id+'';
$("#abc").append(a1).trigger('create');
}
}
});
This pattern matches only number values
var reg = new RegExp('^[0-9]+$');
You can use regular expression pattern to check if id is number or not.
var checkId = new RegExp('\d*');
\d A digit: [0-9]
d* zero or more times
Related
I want to extract email address from the Html String. First I extract the text from html string then pass the returning string into regular expression to search for email address.
import 'package:html/parser.dart';
import 'package:flutter/material.dart';
String _parseString(String htmlString) {
var document = parse(htmlString);
String parsedString = parse(document.body.text).documentElement.text;
return parsedString;
}
String _parseEmailString(String htmlString) {
var document = parse(htmlString);
String parsedString = parse(document.body.text).documentElement.text;
RegExp exp = new RegExp(
r"^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))#((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$",
caseSensitive: false,
multiLine: false,
);
Iterable<RegExpMatch> matches = exp.allMatches('WS://127.0.0.1:56789');
print("hasMatch : " + exp.firstMatch("shahryar.rsm#gmail.com").toString());
var matches2 = "hasMatch : " + exp.stringMatch(parsedString).toString();
return matches2;
}
class HtmlToText extends StatelessWidget {
#override
Widget build(BuildContext context) {
String string =
'<p style=\"text-align: center\"><strong>The CV Club</strong> is a professional writing service that specialise in tailoring CVs, cover letters and more to your desired industry/ job role.</p>\n<p style=\"text-align: center\">The internet is full of dull CV templates, all exactly the same as each other. That’s why at <strong>The CV Club</strong>, we professionally tailor your CV to be as individual as you are and not at extortionate prices!</p>\n<p style=\"text-align: center\">We offer a FREE CV review and will give you constructive feedback on your current CV!</p>\n<p>Contact us on;</p>\n<p><strong>Website: https://www.thecvclub.org/</strong></p>\n<p><strong>Email: thecvclub#gmail.com</strong></p>\n<p><strong>Twitter: thecvclub_</strong></p>\n<p><img data-attachment-id=\"1055\" data-permalink=\"https://soleentrepreneur.co.uk/happy-world-book-day/\" data-orig-file=\"https://i2.wp.com/soleentrepreneur.co.uk/wp-content/uploads/2019/02/Happy-World-Book-Day.png?fit=800%2C800&ssl=1\" data-orig-size=\"800,800\" data-comments-opened=\"1\" data-image-meta=\"{"aperture":"0","credit":"","camera":"","caption":"","created_timestamp":"0","copyright":"","focal_length":"0","iso":"0","shutter_speed":"0","title":"","orientation":"0"}\" data-image-title=\"Happy World Book Day!\" data-image-description=\"\" data-medium-file=\"https://i2.wp.com/soleentrepreneur.co.uk/wp-content/uploads/2019/02/Happy-World-Book-Day.png?fit=300%2C300&ssl=1\" data-large-file=\"https://i2.wp.com/soleentrepreneur.co.uk/wp-content/uploads/2019/02/Happy-World-Book-Day.png?fit=800%2C800&ssl=1\" class=\"alignnone size-medium wp-image-1055 alignleft\" src=\"https://i1.wp.com/soleentrepreneur.co.uk/wp-content/uploads/2019/02/Happy-World-Book-Day-300x300.png?resize=300%2C300\" alt=\"\" width=\"300\" height=\"300\" srcset=\"https://i2.wp.com/soleentrepreneur.co.uk/wp-content/uploads/2019/02/Happy-World-Book-Day.png?resize=300%2C300&ssl=1 300w, https://i2.wp.com/soleentrepreneur.co.uk/wp-content/uploads/2019/02/Happy-World-Book-Day.png?resize=80%2C80&ssl=1 80w, https://i2.wp.com/soleentrepreneur.co.uk/wp-content/uploads/2019/02/Happy-World-Book-Day.png?resize=768%2C768&ssl=1 768w, https://i2.wp.com/soleentrepreneur.co.uk/wp-content/uploads/2019/02/Happy-World-Book-Day.png?resize=36%2C36&ssl=1 36w, https://i2.wp.com/soleentrepreneur.co.uk/wp-content/uploads/2019/02/Happy-World-Book-Day.png?resize=180%2C180&ssl=1 180w, https://i2.wp.com/soleentrepreneur.co.uk/wp-content/uploads/2019/02/Happy-World-Book-Day.png?resize=705%2C705&ssl=1 705w, https://i2.wp.com/soleentrepreneur.co.uk/wp-content/uploads/2019/02/Happy-World-Book-Day.png?resize=120%2C120&ssl=1 120w, https://i2.wp.com/soleentrepreneur.co.uk/wp-content/uploads/2019/02/Happy-World-Book-Day.png?resize=450%2C450&ssl=1 450w, https://i2.wp.com/soleentrepreneur.co.uk/wp-content/uploads/2019/02/Happy-World-Book-Day.png?resize=640%2C640&ssl=1 640w, https://i2.wp.com/soleentrepreneur.co.uk/wp-content/uploads/2019/02/Happy-World-Book-Day.png?resize=50%2C50&ssl=1 50w, https://i2.wp.com/soleentrepreneur.co.uk/wp-content/uploads/2019/02/Happy-World-Book-Day.png?w=800&ssl=1 800w\" sizes=\"(max-width: 300px) 100vw, 300px\" data-recalc-dims=\"1\" /> <img data-attachment-id=\"1056\" data-permalink=\"https://soleentrepreneur.co.uk/lets-celebrate/\" data-orig-file=\"https://i1.wp.com/soleentrepreneur.co.uk/wp-content/uploads/2019/02/Lets-celebrate.png?fit=800%2C800&ssl=1\" data-orig-size=\"800,800\" data-comments-opened=\"1\" data-image-meta=\"{"aperture":"0","credit":"","camera":"","caption":"","created_timestamp":"0","copyright":"","focal_length":"0","iso":"0","shutter_speed":"0","title":"","orientation":"0"}\" data-image-title=\"Let’s celebrate\" data-image-description=\"\" data-medium-file=\"https://i1.wp.com/soleentrepreneur.co.uk/wp-content/uploads/2019/02/Lets-celebrate.png?fit=300%2C300&ssl=1\" data-large-file=\"https://i1.wp.com/soleentrepreneur.co.uk/wp-content/uploads/2019/02/Lets-celebrate.png?fit=800%2C800&ssl=1\" class=\"alignnone size-medium wp-image-1056 alignleft\" src=\"https://i0.wp.com/soleentrepreneur.co.uk/wp-content/uploads/2019/02/Lets-celebrate-300x300.png?resize=300%2C300\" alt=\"\" width=\"300\" height=\"300\" srcset=\"https://i1.wp.com/soleentrepreneur.co.uk/wp-content/uploads/2019/02/Lets-celebrate.png?resize=300%2C300&ssl=1 300w, https://i1.wp.com/soleentrepreneur.co.uk/wp-content/uploads/2019/02/Lets-celebrate.png?resize=80%2C80&ssl=1 80w, https://i1.wp.com/soleentrepreneur.co.uk/wp-content/uploads/2019/02/Lets-celebrate.png?resize=768%2C768&ssl=1 768w, https://i1.wp.com/soleentrepreneur.co.uk/wp-content/uploads/2019/02/Lets-celebrate.png?resize=36%2C36&ssl=1 36w, https://i1.wp.com/soleentrepreneur.co.uk/wp-content/uploads/2019/02/Lets-celebrate.png?resize=180%2C180&ssl=1 180w, https://i1.wp.com/soleentrepreneur.co.uk/wp-content/uploads/2019/02/Lets-celebrate.png?resize=705%2C705&ssl=1 705w, https://i1.wp.com/soleentrepreneur.co.uk/wp-content/uploads/2019/02/Lets-celebrate.png?resize=120%2C120&ssl=1 120w, https://i1.wp.com/soleentrepreneur.co.uk/wp-content/uploads/2019/02/Lets-celebrate.png?resize=450%2C450&ssl=1 450w, https://i1.wp.com/soleentrepreneur.co.uk/wp-content/uploads/2019/02/Lets-celebrate.png?resize=640%2C640&ssl=1 640w, https://i1.wp.com/soleentrepreneur.co.uk/wp-content/uploads/2019/02/Lets-celebrate.png?resize=50%2C50&ssl=1 50w, https://i1.wp.com/soleentrepreneur.co.uk/wp-content/uploads/2019/02/Lets-celebrate.png?w=800&ssl=1 800w\" sizes=\"(max-width: 300px) 100vw, 300px\" data-recalc-dims=\"1\" /> <img data-attachment-id=\"1059\" data-permalink=\"https://soleentrepreneur.co.uk/need-help-with-your-cv_/\" data-orig-file=\"https://i1.wp.com/soleentrepreneur.co.uk/wp-content/uploads/2019/02/Need-help-with-your-CV_.png?fit=800%2C800&ssl=1\" data-orig-size=\"800,800\" data-comments-opened=\"1\" data-image-meta=\"{"aperture":"0","credit":"","camera":"","caption":"","created_timestamp":"0","copyright":"","focal_length":"0","iso":"0","shutter_speed":"0","title":"","orientation":"0"}\" data-image-title=\"Need help with your CV_\" data-image-description=\"\" data-medium-file=\"https://i1.wp.com/soleentrepreneur.co.uk/wp-content/uploads/2019/02/Need-help-with-your-CV_.png?fit=300%2C300&ssl=1\" data-large-file=\"https://i1.wp.com/soleentrepreneur.co.uk/wp-content/uploads/2019/02/Need-help-with-your-CV_.png?fit=800%2C800&ssl=1\" class=\"alignnone size-medium wp-image-1059 alignleft\" src=\"https://i0.wp.com/soleentrepreneur.co.uk/wp-content/uploads/2019/02/Need-help-with-your-CV_-300x300.png?resize=300%2C300\" alt=\"\" width=\"300\" height=\"300\" srcset=\"https://i1.wp.com/soleentrepreneur.co.uk/wp-content/uploads/2019/02/Need-help-with-your-CV_.png?resize=300%2C300&ssl=1 300w, https://i1.wp.com/soleentrepreneur.co.uk/wp-content/uploads/2019/02/Need-help-with-your-CV_.png?resize=80%2C80&ssl=1 80w, https://i1.wp.com/soleentrepreneur.co.uk/wp-content/uploads/2019/02/Need-help-with-your-CV_.png?resize=768%2C768&ssl=1 768w, https://i1.wp.com/soleentrepreneur.co.uk/wp-content/uploads/2019/02/Need-help-with-your-CV_.png?resize=36%2C36&ssl=1 36w, https://i1.wp.com/soleentrepreneur.co.uk/wp-content/uploads/2019/02/Need-help-with-your-CV_.png?resize=180%2C180&ssl=1 180w, https://i1.wp.com/soleentrepreneur.co.uk/wp-content/uploads/2019/02/Need-help-with-your-CV_.png?resize=705%2C705&ssl=1 705w, https://i1.wp.com/soleentrepreneur.co.uk/wp-content/uploads/2019/02/Need-help-with-your-CV_.png?resize=120%2C120&ssl=1 120w, https://i1.wp.com/soleentrepreneur.co.uk/wp-content/uploads/2019/02/Need-help-with-your-CV_.png?resize=450%2C450&ssl=1 450w, https://i1.wp.com/soleentrepreneur.co.uk/wp-content/uploads/2019/02/Need-help-with-your-CV_.png?resize=640%2C640&ssl=1 640w, https://i1.wp.com/soleentrepreneur.co.uk/wp-content/uploads/2019/02/Need-help-with-your-CV_.png?resize=50%2C50&ssl=1 50w, https://i1.wp.com/soleentrepreneur.co.uk/wp-content/uploads/2019/02/Need-help-with-your-CV_.png?w=800&ssl=1 800w\" sizes=\"(max-width: 300px) 100vw, 300px\" data-recalc-dims=\"1\" /></p>\n<p> </p>\n';
return Scaffold(
appBar: AppBar(),
body: Column(children: <Widget>[
SelectableText(
_parseString('$string'),
),
Text(_parseEmailString('$string'))
]));
}
}
Found out using wrong regex Regular Expression was
r"[a-zA-Z0-9-_.]+#[a-zA-Z0-9-_.]+"
In one of my mongodb collection, I have a date string that has a mm/dd/yyyy format. Now, I want to query the 'mm' string.
Example, 05/20/2016 and 04/05/2015.
I want to get the first 2 characters of the string and query '05'. With that, the result I will get should only be 05/20/2016.
How can I achieve this?
Thanks!
For a regex solution, the following will suffice
var search = "05",
rgx = new RegExp("^"+search); // equivalent to var rgx = /^05/;
db.collection.find({ "leave_start": rgx });
Testing
var leave_start = "05/06/2016",
test = leave_start.match(/^05/);
console.log(test); // ["05", index: 0, input: "05/06/2016"]
console.log(test[0]); // "05"
or
var search = "05",
rgx = new RegExp("^"+search),
leave_start = "05/12/2016";
var test = leave_start.match(rgx);
console.log(test); // ["05", index: 0, input: "05/06/2016"]
console.log(test[0]); // "05"
Another alternative is to use the aggregation framework and take advantage of the $substr operator to extract the first 2 characters of a field and then the $match operator will filter documents based on the new substring field above:
db.collection.aggregate([
{
"$project": {
"leaves_start": 1,
"monthSubstring": { "$substr": : [ "$leaves_start", 0, 2 ] }
}
},
{ "$match": { "monthSubstring": "05" } }
])
I have a problem when using Regex. I have a html document which create an anchor link when it matches condition.
An example html:
Căn cứ Luật Tổ chức HĐND và UBND ngày 26/11/2003;
Căn cứ Nghị định số 63/2010/NĐ-CP ngày 08/6/2010 của Chính phủ về
kiểm soát thủ tục hành chính;
Căn cứ Quyết định số 165/2011/QĐ-UBND ngày 06/5/2011 của UBND tỉnh
ban hành Quy định kiểm soát thủ tục hành chính trên địa bàn tỉnh;
Căn cứ Quyết định số 278/2011/QĐ-UBND ngày 02/8/2011 của UBND tỉnh
ban hành Quy chế phối hợp thực hiện thống kê, công bố, công khai thủ
tục hành chính và tiếp nhận, xử lý phản ánh, kiến nghị của cá nhân, tổ
chức về quy định hành chính trên địa bàn tỉnh;
Xét đề nghị của Giám đốc Sở Công Thương tại Tờ trình số
304/TTr-SCT ngày 29 tháng 5 năm 2013
I want to match these bold texts and make anchor links from these. If it has, try ignore. Link example 63/2010/NĐ-CP
var matchLegals = new Regex(#"(?:[\d]+\/?)\d+\/[a-z\dA-Z_ÀÁÂÃÈÉÊÌÍÒÓÔÕÙÚĂĐĨŨƠàáâãèéêìíòóôõùúăđĩũơƯĂẠẢẤẦẨẪẬẮẰẲẴẶẸẺẼỀỀỂưăạảấầẩẫậắằẳẵặẹẻẽềềểỄỆỈỊỌỎỐỒỔỖỘỚỜỞỠỢỤỦỨỪễệỉịọỏốồổỗộớờởỡợụủứừỬỮỰỲỴÝỶỸửữựỳỵỷỹ\-]+", RegexOptions.Compiled);
var doc = new HtmlDocument();
doc.LoadHtml(htmlString);
var allElements = doc.DocumentNode.SelectSingleNode("//div[#class='main-content']").Descendants();
foreach (var node in allElements)
{
var matches = matchLegals.Matches(node.InnerHtml);
foreach (Match m in matches)
{
var k = m.Value;
//dont know what to do
}
}
What can i do this
Many thanks.
I assume your regex pattern is OK and works. Another assumption is that node.InnerHtml doesn't contain any <a> tags already encompassing any of the potential matches.
In this case, it's as simple as doing something like this:
node.InnerHtml = Regex.Replace(node.InnerHtml, "[your pattern here]", "<a href='query=$&'>$&</a>");
...
doc.Save("output.html");
Note, that you may need to work on the href component - I'm unsure how your link should be built.
you match text and replace:
<script>
var s = '...';
var matchs = s.match(/\d{2,3}\/\d{4}\/[a-zA-Z\-áàảãạăâắằấầặẵẫậéèẻẽẹêếềểễệóòỏõọôốồổỗộơớờởỡợíìỉĩịđùúủũụưứửữựÀÁÂÃÈÉÊÌÍÒÓÔÕÙÚĂĐĨŨƠƯĂẠẢẤẦẨẪẬẮẰẲẴẶẸẺẼÊỀỂỄỆỈỊỌỎỐỒỔỖỘỚỜỞỠỢỤỨỪỬỮỰỲỴÝỶỸửữựỵỷỹ]+/gi);
if (matchs != null) {
for(var i=0; i<matchs.length;i++){
var val = matchs[i];
s = s.replace(val, '<a href="?key=' + val + '"/>' + val + '</a>');
}
}
document.write(s);
</script>
#Shaamaan thank for your advice. After few hours of coding, it works now
var content = doc.DocumentNode.SelectSingleNode("//div[#class='main-content']");
var items = content.SelectNodes(".//text()[normalize-space(.) != '']");
foreach (HtmlNode node in items)
{
if (!matchLegals.IsMatch(node.InnerText) || node.ParentNode.Name == "a")
{
continue;
}
var texts = node.InnerHtml.Trim();
node.InnerHtml = matchLegals.Replace(texts, a => string.Format("<a href='/search?q={0}'>{0}</a>",a.Value));
}
I am so sorry, but after one day researching and trying all different combinations and npm packages, I am still not sure how to deal with the following task.
Setup:
MongoDB 2.6
Node.JS with Mongoose 4
I have a schema like so:
var trackingSchema = mongoose.Schema({
tracking_number: String,
zip_code: String,
courier: String,
user_id: Number,
created: { type: Date, default: Date.now },
international_shipment: { type: Boolean, default: false },
delivery_info: {
recipient: String,
street: String,
city: String
}
});
Now user gives me a search string, a rather an array of strings, which will be substrings of what I want to search:
var search = ['15323', 'julian', 'administ'];
Now I want to find those documents, where any of the fields tracking_number, zip_code, or these fields in delivery_info contain my search elements.
How should I do that? I get that there are indexes, but I probably need a compound index, or maybe a text index? And for search, I then can use RegEx, or the $text $search syntax?
The problem is that I have several strings to look for (my search), and several fields to look in. And due to one of those aspects, every approach failed for me at some point.
Your use case is a good fit for text search.
Define a text index on your schema over the searchable fields:
trackingSchema.index({
tracking_number: 'text',
zip_code: 'text',
'delivery_info.recipient': 'text',
'delivery_info.street': 'text',
'delivery_info.city': 'text'
}, {name: 'search'});
Join your search terms into a single string and execute the search using the $text query operator:
var search = ['15232', 'julian'];
Test.find({$text: {$search: search.join(' ')}}, function(err, docs) {...});
Even though this passes all your search values as a single string, this still performs a logical OR search of the values.
Why just dont try
var trackingSchema = mongoose.Schema({
tracking_number: String,
zip_code: String,
courier: String,
user_id: Number,
created: { type: Date, default: Date.now },
international_shipment: { type: Boolean, default: false },
delivery_info: {
recipient: String,
street: String,
city: String
}
});
var Tracking = mongoose.model('Tracking', trackingSchema );
var search = [ "word1", "word2", ...]
var results = []
for(var i=0; i<search.length; i++){
Tracking.find({$or : [
{ tracking_number : search[i]},
{zip_code: search[i]},
{courier: search[i]},
{delivery_info.recipient: search[i]},
{delivery_info.street: search[i]},
{delivery_info.city: search[i]}]
}).map(function(tracking){
//it will push every unique result to variable results
if(results.indexOf(tracking)<0) results.push(tracking);
});
Okay, I came up with this.
My schema now has an extra field search with an array of all my searchable fields:
var trackingSchema = mongoose.Schema({
...
search: [String]
});
With a pre-save hook, I populate this field:
trackingSchema.pre('save', function(next) {
this.search = [ this.tracking_number ];
var searchIfAvailable = [
this.zip_code,
this.delivery_info.recipient,
this.delivery_info.street,
this.delivery_info.city
];
for (var i = 0; i < searchIfAvailable.length; i++) {
if (!validator.isNull(searchIfAvailable[i])) {
this.search.push(searchIfAvailable[i].toLowerCase());
}
}
next();
});
In the hope of improving performance, I also index that field (also the user_id as I limit search results by that):
trackingSchema.index({ search: 1 });
trackingSchema.index({ user_id: 1 });
Now, when searching I first list all substrings I want to look for in an array:
var andArray = [];
var searchTerms = searchRequest.split(" ");
searchTerms.forEach(function(searchTerm) {
andArray.push({
search: { $regex: searchTerm, $options: 'i'
}
});
});
I use this array in my find() and chain it with an $and:
Tracking.
find({ $and: andArray }).
where('user_id').equals(userId).
limit(pageSize).
skip(pageSize * page).
exec(function(err, docs) {
// hooray!
});
This works.
I have a custom regex method:
$.validator.addMethod(
"dateRegex",
function(value, element, regexp) {
var re = new RegExp(regexp);
return this.optional(element) || re.test(value);
},
"Date must be in the format MM/DD/YYYY"
);
I've got jQuery validation on a date field that looks like this:
rules:
date:
{
required: true,
dateRegex: '^(0[1-9]|1[012])[- //.](0[1-9]|[12][0-9]|3[01])[- //.](19|20)\d\d$',
maxlength: 10
}
}
messages: {
lossDate: {
required: "Unable to proceed, search field is empty"
}
}
When I enter a valid date, for example 08/06/2013, "Date must be in the format MM/DD/YYYY" is displayed. Does anyone see a mistake in my regex, or is the problem outside of that?
The test data passes here: http://regexpal.com/
Also, I have the following working in my app:
$.validator.addMethod(
"regex",
function(value, element, regexp) {
var re = new RegExp(regexp);
return this.optional(element) || re.test(value);
},
"Invalid number of characters entered."
);
number:
{
required: true,
regex: '^(.{7}|.{9}|.{11}|.{12}|.{15})$'
},...
I guess that plugin doesn't want strings for regexes. Instead of a string literal, put a regex literal:
…,
dateRegex: /^(0[1-9]|1[012])[- \/.](0[1-9]|[12][0-9]|3[01])[- \/.](19|20)\d\d$/,
…
You also can simplify the function then:
function(value, element, regexp) {
return this.optional(element) || regexp.test(value);
}