How can count the number of consecutive Spaces at the beginning of each line?It can be implemented with a formula or a regex

I only know how to use this formula, but it's definitely not right.I don't want to do it in a circular way.
Length(txt)-Length(Substitute(txt, " ", ""))
Thanks!
Basic Data Analysis and ModelingWindows回复: How can count the number of consecutive Spaces at the beginning of each line? Scripting Guide
Introduction to Writing JSL Scripts
What JSL Can Do for You
Help with Learning JSL
The Scripting Index
Let JMP Teach You JSL
JSL Terminology
Basic JSL Syntax
Scripting Guide Conventions
Get Started
Capture a Script for an Analysis Report
Capture a Script for a Data Table
Capture a Script to Import a File
Glue Scripts TogetherRe: How can count the number of consecutive Spaces at the beginning of each line?This is similar to your code, but I would suspect it will more correct, because your code will substitute the blank characters within the text.
txt = " Scripting Guide";
numLeadingBlanks = Length( txt ) - Length( Trim( txt ) );
It can also return an error if there are trailing blanks.
This should correct for that issue
txt = " Scripting Guide ";
numLeadingBlanks = Contains( txt, Substr( Trim( txt ), 1, 1 ) ) - 1;