Hello.

Explain to me why this code is below:

'tag#id.class@attr'.match(/\.|\@|\#(.+?)\.|\@|\#?^/gi) 

always displays:

 ["", "#id.", "@"] 

When I expected to receive:

 ["id", "class", "attr"] 

What's my mistake? It seems to indicate that the infa is stretched, which lies between: \. either with these \@ or these \# characters.

    2 answers 2

    Well, something like this)

     $(function() { var arr = 'tag#id.class@attr'.match(/[#@.]([^#@.]*)/g); for(var i = 0; i < arr.length; i++){ arr[i] = arr[i].replace(/^.(.+)$/, '$1') }; alert(arr) }); 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 

    • Works on 5+ =) Thank you! - dgd hsk

    here is the service for testing regular expressions rubular.com

    Try this: 'tag#id.class@attr'.match(/\#(.+?)\.(.+?)\@(.+)/gi)