Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery :contains(regex)? [duplicate]

Is it possible to have a jQuery selector where the :contains() is a regular expression?

I need to select an element where the innerHTML contains something findable through regex?

I know it's a short question. My apologies.

var t = $("#id a:containsRegex("/[0-9]/g")"); // Doesn't work 
like image 724
Edge Avatar asked Apr 08 '14 07:04

Edge


1 Answers

Try ,

var regex = new RegExp("[0-9]"); // expression here  $("#id a").filter(function () {     return regex.test($(this).text());  }); 
like image 118
Deepak Ingole Avatar answered Oct 08 '22 14:10

Deepak Ingole