Add a word break to long words...

0 views
Skip to first unread message

Ciaran

unread,
May 27, 2009, 8:32:21 AM5/27/09
to Regex
Hi I'm trying to write a regexp that adds a <wbr> word break tag to
all words in a html string that are longer than 10 characters. The
problem is the regexp match needs to ignore all strings inside < and >
as they are obviously part of the code itself.
Here's what I have so far but it doesn't seem to match correctly:

(?<!<)(\S{10,200})(?!>)

By the way, I'm using this site a lot lately which is very cool for
regex beginners:
http://gskinner.com/RegExr/


Thanks a lot,
Ciarán

cronoklee

unread,
May 29, 2009, 11:24:54 AM5/29/09
to Regex
Here's some sample search text.

<br /><br />This is a test message with <a href="http://
groups.google.ie/group/regex/browse_thread/thread/
7e0975969ecfc420">&#9632; long links</a> and people doing annoying
things like
COOL!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
<br /><h2>or</
h2>yeeeeeeeeeeeeyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
which destroys <i>my layout</i>

Cheers,
Ciarán

cronoklee

unread,
Jun 11, 2009, 9:26:12 AM6/11/09
to Regex
Anyone?

Eugeny Sattler

unread,
Jun 17, 2009, 3:46:14 AM6/17/09
to re...@googlegroups.com
Hi,
sorry for late reply...though....
Try this approach

#free spacing regex
</[a-z][0-9]?> #closing html tag, used just as a milestone
(.(?<!\<))+ #any char but not the one that has "<" to
#the left of it, repeated many times, thus
#making a loooong word
<[a-z][0-9]?> # opening html tag, used just as a milestone

this one catches this snippet from your example

</h2>yeeeeeeeeeeeeyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
which destroys <i>

Note: i deleted line breaks from your text before applying my regex

--
Regards, Eugeny
--
best regards,          Eugeny

cronoklee

unread,
Jun 19, 2009, 11:17:29 AM6/19/09
to Regex
Great, Thanks for the reply. At first glance it looks good but it
should catch all long words that are not between html <braces>. So it
should also catch "COOL!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" from my
sample. I'll have a look at it properly and let you know anyway.
Thanks again,
Ciarán
Reply all
Reply to author
Forward
0 new messages