Hi, I want to take the first comma seperated value from that string.
"Lines.No;StartPos=3;RightAligned;MaxLength =2"
I used "\b.*\;"
regex to take "Lines.No"
. But the result is
"Lines.No;StartPos=3;RightAligned;"
thanks.
Hi, I want to take the first comma seperated value from that string.
"Lines.No;StartPos=3;RightAligned;MaxLength =2"
I used "\b.*\;"
regex to take "Lines.No"
. But the result is
"Lines.No;StartPos=3;RightAligned;"
thanks.
First, anchor the search at the start of the string. Then use a lazy quantifier: ^\b.*?;
or a negated character class: ^\b[^;];
But careful: Could semicolons appear in your CSV fields (in quoted strings)? If so, regexes can still be made to work, but will be a lot more complicated - a CSV parser would be much better.
I know you are looking fore a regex, but if you have delimited string, use your favourite language's split() function, eg in Python
>>> s="Lines.No;StartPos=3;RightAligned;MaxLength =2"
>>> s.split(";")[0]
'Lines.No'
Much simpler than regex. Similarly, explode() in PHP, split() in Perl, Split() in C# , etc
You could do this way too, in python
>>> x="Lines.No;StartPos=3;RightAligned;MaxLength =2"
>>> x[:x.find(";")]
'Lines.No'