Why not just use a capture group and check the length:
<html> <head> </head> <body> <script language="javascript"> var myStr = " hello"; var myRe = /^(\s*)(.*)$/; var match = myRe.exec(myStr); alert(match[1].length); </script> </body> </html
This may be followed by code that acts on your three cases, length 0, 1, or otherwise, and acts on the rest of the line.
You should treat regular expressions as a tool, not a whole set of tools.
paxdiablo
source share