Line Indentation
beginnerCaptures the indentation level of each line.
whitespaceindentationformattingcode
Pattern
/^([ \t]+)/gmTry It
0 of 5 strings matched
Explanation
Captures leading spaces and tabs at the start of each line. Group 1 contains the indentation string for measuring indent level.
Test Strings
Matching
- two spaces
- one tab
- four spaces
Non-matching
- no indent
Language Compatibility
| Language | Support |
|---|---|
| JS | Full support |
| PYTHON | Full support |
| JAVA | Full support |
| PHP | Full support |
| GO | Full support |
Code Snippets
const regex = /^([ \t]+)/gm;
const text = "your text here";
const matches = text.match(regex);
console.log(matches);