Jose Luis <> writes:
> Given the string "one;two;three;four...", is there a easy way to
> print "one":
Not using regular expressions I would use the split function to
archieve this.
> $ echo "one;two;three;four..."|perl -e 'while(<>){$_ =~ /^(.*)(\
(.*)
> $/ && print $1}'
> one;two;three
But what you are missing is the non-greedy variant of the initial
*. By default quantifiers af greedy, that is that they match as much
as posible. If you instead uses (.*?) it will match as little as
posible.
Another soulution woulb be to replace (.*) with ([^;]*). This matches
as many non-semicolon as possible.
//Makholm