Sample string, at the beginning of line is TAB, and between maxLen = 256
and ;
are either spaces or tabs.
I need to match only the "TABmaxLen = 256"
portion irgnoring the rest
maxLen = 256 ; Maximum string size 1
My regex doesn't work for some reason because it matches all up to ;
includign spaces and tabs, but I need to ignore spaces and tabs before and including ;
(\t.*)(?!\s\t);
TABmaxLen = 256
is just a sample, it should match anything except spaces and tabs that follow and end with ;
EDIT:
More information:
This is sample ASM code, per line, I want to match only those lines which have inline comments, but only code, not spaces and tabs and not inline comments.
; a function result to a C program.
option casemap:none
nl = 10 ; ASCII code for newline
maxLen = 256 ; Maximum string size 1
.data
titleStr byte 'Listing 1 - 8', 0
regex should match from example above these 2 (including starting tab):
nl = 10
maxLen = 256
CodePudding user response:
You could match the tab, then capture any char except ;
and match the ending whitespace chars until the ;
\t([^\s;][^;]*?)\s*;
Explanation
\t
Match a tab(
Capture group 1[^\s;][^;]*?
Match a single non whitespace char other than;
followed by matching any char other than;
non greedy
)
Close group 1\s*;
Match optional whitespace chars followed by;
See a regex101 demo.
Another option for a match only and lookarounds and asserting 1 or more whitespace chars at the end followed by ;
(?<=\t)[^\s;].*?(?=\s ;)
See another regex101 demo