Jump to content

jQuery regular expression


brianlange

Recommended Posts

The regular expression in jQuery to test for for HTML strings and ID strings is

/^[^<]*(<[\w\W]+>)[^>]*$|^#([\w-]+)$/

 

What I don't understand is why the return value for  regExp.exec('#test') returns #test,,test

I don't understand why it returns an empty string for the second result?  When I only use the second half of the expression /^#([\w-]+)$/  the return value is '#test','test' and when I only use the first half of the expression

/^[^<]*(<[\w\W]+>)[^>]*$/ the return value is null.  Can someone explain this?

 

Thanks,

 

Brian

Link to comment
https://forums.phpfreaks.com/topic/200177-jquery-regular-expression/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.