l i n u x - u s e r s - g r o u p - o f - d a v i s
L U G O D
 
Next Meeting:
November 4: Social gathering
Next Installfest:
TBD
Latest News:
Oct. 24: LUGOD election season has begun!
Page last updated:
2001 Dec 30 17:10

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] Looking for 2 cool regexs
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vox-tech] Looking for 2 cool regexs



Ok, I've got another:

I have a really long string (2000ish chars), I want to break it into
multiple strings of 80 chars or less.
The Catch is, I need to break it on a space (' '), hence the "or less".  It
seems, I should be able to
use a regex on this.

Currently I do it like:

$lineLength = 80;
$line = #some really long string#;

# essentially while the line is longer than 80 chars
# find the right most ' ' or ',' up to a maximum of 80 chars
# from the beginning
# break off that piece of the string and start over
while (length($line) > $lineLength) {
   my $space = rindex(substr($line,0,$lineLength),' ') ||
      rindex(substr($line,0,$lineLength),',');
      print substr($line,0,$space)."\n";
      substr($line,0,$space) = '';
}
print "$line\;\n";

Seems like I should be able to do it (somehow) with a regex sorta like

foreach ($line =~ m/(" ")/g) { # but somehow specify a length
    print $_;
}

Any ideas?
Thanks
Jay


----- Original Message -----
From: "Ted Deppner" <ted@psyber.com>
To: <vox-tech@franz.mother.com>
Sent: Friday, September 14, 2001 3:36 AM
Subject: Re: [vox-tech] Looking for 2 cool regexs


> On Thu, Sep 13, 2001 at 11:05:48AM -0500, Jay Strauss wrote:
> > find any CREATEwhitespaceTABLEanycharsnot; and replace them with ''.
the
> > whole lot of it has to start at a word boundary.
>
> right on...
>
> > I've never done this before, I didn't know you could produce a  list
from a
> > match command.
>
> It's nifty...  the concept is an expansion on
>   ($a,$b,$c) = $var =~ m/(re1)(re2)(re3)/
>   (where $1,$2,$3 are returned in a list context)
>
> --
> Ted Deppner
> http://www.psyber.com/~ted/


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


LinkedIn
LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
facebook
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
Appahost Applications
For a significant contribution towards our projector, and a generous donation to allow us to continue meeting at the Davis Library.