Searching using regex for number of dates

Searching using regex for number of dates

iamstevevaniamstevevan Posts: 8Questions: 4Answers: 0

I am trying to search through my datatable to find out how many rows are time stamped as a certain month. I am doing this by:

var table = $('#example').DataTable();

var monthRegex = '';
var monthResults

for (i = 1; i <= 12; i++) {     
    monthRegex = '^(['+i+']\/[1-9]{1,2}\/2014)$'
    monthResults = table.column(2).search( monthRegex, true, true );
}

Regex works, as tested at regex101.com.

What am I missing?

Answers

  • iamstevevaniamstevevan Posts: 8Questions: 4Answers: 0

    I also should mention I do not want to redraw.

  • iamstevevaniamstevevan Posts: 8Questions: 4Answers: 0

    Figured this out. I am only applying the search. I needed to add

    var monthRegex = '';
    var monthResults

    for (i = 1; i <= 12; i++) {
    monthRegex = '^(['+i+']\/[1-9]{1,2}\/2014)$'
    monthResults = table.column(2).search( monthRegex, true, true );
    monthResults = table
    .columns( [2], { search: 'applied', order:'current', page:'all' } )
    .data();
    }

This discussion has been closed.