Javascript Regex to return only a range of items -


i have requirement regex expression should return immediate children of it's parent. eg. if parent denoted classname "level-0", it's immediate children classname can "level-0-0, level-0-1......,level-0-10" etc.

i have regex in javascript intended return immediate child, it's not working. please find regex below.

$('tr').filter(function(){   return this.classname.match(/level-0[-\d+]{1,1}/) }) // result below. [<tr class=​"fundrow level-0-0 child" style=​"display:​ table-row;​">​…​</tr>​, <tr class=​"fundrow level-0-0-0 child" style=​"display:​ table-row;​">​…​</tr>​, <tr class=​"fundrow level-0-0-0-0 child" style=​"display:​ table-row;​">​…​</tr>​, <tr class=​"fundrow level-0-0-0-1 child" style=​"display:​ table-row;​">​…​</tr>​, <tr class=​"fundrow level-0-0-1 child" style=​"display:​ table-row;​">​…​</tr>​, <tr class=​"fundrow level-0-1 child" style=​"display:​ table-row;​">​…​</tr>​] 

here parent class "level-0". expecting "level-0-0 ,level-0-1". in regex "[-\d]+{1,1}", trying specify level-0 should followed single occurrence of '-' followed integer. not able restrict occurrence.

it below,

/level-0-\d+\s/ 

use word boundary if necessary.

/\blevel-0-\d+\s/ 

Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -