473,385 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

RegExp thats too complicated for me

I am using a javascript rich-text-editor to allow a content writer to
easily see what there content looks like, however, the content
management system that I have made would like to accept bbcode style
text. The problem is the text editor ueses spans with the style
attribute to get the desired effect(it uses the mozilla rich-text
editing api), I am looking at changing very complex spans:
<span style="text-decoration: underline, font-weight: bolder,
text-style: italic">
some text</span>
into very simple bbcode:
some text

I think I can manage links, horizontal rules and h# tags, but this
seems a little over my head, I cannot think of a way that I know will
work, and I think the answer is a regular expression(this executed on
the string before it is sent to the server), but I am not sure, and
would like some input, as opposed to struggling around with some crazy
thing that I probably won't be able to get to work.
Jul 23 '05 #1
2 1213
On 15 Aug 2004 14:09:48 -0700, infinull <in******@yahoo.com> wrote:

[snip]
<span style="text-decoration: underline, font-weight: bolder,
text-style: italic">
some text</span>
into very simple bbcode:
some text


[snip]

This might only be a partial solution. If it is, you'll need to provide
some more information. For example, will you be sending strings with many
such tags, or just one? If it's many, what could appear adjacent to the
SPAN elements?

/<span\s+style\s*=\s*"(.+)"\s*>(.+)<\/span>/

The regular expression above will match the SPAN you have shown above,
remembering the content inside the style attribute, and the content of the
SPAN.

The following regular expressions will match the text-decoration,
font-weight, and text-style properties, respectively. Note that they don't
check what value those properties are assigned.

/text\-decoration:\s+[a-z]+/
/font\-weight:\s+[a-z]+/
/text\-style:\s+[a-z]+/

A rather artificial example:

var html = '<span style="font-weight: bolder;' +
' text-decoration: underline; text-style: italic">some text<\/span>';
var s = /<span\s+style\s*=\s*"(.+)"\s*>(.+)<\/span>/.exec(html),
c = s[2],
u = /text\-decoration:\s+[a-z]+/.test(s[1]),
b = /font\-weight:\s+[a-z]+/.test(s[1]),
i = /text\-style:\s+[a-z]+/.test(s[1]);

if(u) {c = '' + c + '';}
if(i) {c = '' + c + '';}
if(b) {c = '' + c + '';}

alert(c);

You'll have to give that thorough testing, as I cannot: I don't know what
your data will look like.

Hope that helps,
Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail
Jul 23 '05 #2
thanks your a lifesaver, I'll get to that tommorrow, I hope.
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Lukas Holcik | last post by:
Hi everyone! How can I simply search text for regexps (lets say <a href="(.*?)">(.*?)</a>) and save all URLs(1) and link contents(2) in a dictionary { name : URL}? In a single pass if it could....
8
by: gry | last post by:
I have a string like: {'the','dog\'s','bite'} or maybe: {'the'} or sometimes: {} which I'm trying to parse with the re module.
6
by: Mark Johnson | last post by:
Is there a shorthand for this: <xsl:when test="$day2 or $day2 or $day2">
3
by: Jacob Weber | last post by:
If I do a search with a regular expression that uses parenthesized subexpressions, is there a way to find out where it found the subexpressions? For example, say I do: "bb".search(/b(.)/g); ...
4
by: Jon Maz | last post by:
Hi All, I want to strip the accents off characters in a string so that, for example, the (Spanish) word "práctico" comes out as "practico" - but ignoring case, so that "PRÁCTICO" comes out as...
4
by: drasko | last post by:
Hi all. I need to code simple and fast int regexp_match(char *regexp, char *string) function that will follow the expression regexp, and see if there is a matching in the string. If there is, it...
9
by: vbfoobar | last post by:
Hello I am looking for python code that takes as input a list of strings (most similar, but not necessarily, and rather short: say not longer than 50 chars) and that computes and outputs the...
9
by: =?ISO-8859-1?Q?BJ=F6rn_Lindqvist?= | last post by:
With regexps you can search for strings matching it. For example, given the regexp: "foobar\d\d\d". "foobar123" would match. I want to do the reverse, from a regexp generate all strings that could...
8
by: reflex | last post by:
Hi, i have script with pattern (href=?(.*)({1}+)?), where i match any occurence of url and replace hyperlink so i have only anchor in it. var regExp = /href=?(.*)({1}+)?/ig; var wholeContent...
1
by: Orin | last post by:
Hello! I'm using php and have a complicated task, so if someone can understand it then please help me to solve it The task is to make function, that will understand user-inputed regexp and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.