Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Regular expression from JavaScript

Reply
Thread Tools

Regular expression from JavaScript

 
 
Thomas Ardal
Guest
Posts: n/a
 
      09-10-2006
Hi

I need to convert the following string:

!Hello World

to:

*Hello World*

with JavaScript and regular expression. Anyone up for a little help?

Regards,
Thomas


 
Reply With Quote
 
 
 
 
Thomas Ardal
Guest
Posts: n/a
 
      09-10-2006
Actually it would be nice to be able to convert:

!any string

to:

<h1>any string</h1>

as well. So "any string" can be ... ehm any string and the ! should be
converted to <h1> at the beginning of the line and </h1> at the end.

Regards,
Thomas


 
Reply With Quote
 
 
 
 
Evertjan.
Guest
Posts: n/a
 
      09-10-2006
Thomas Ardal wrote on 10 sep 2006 in comp.lang.javascript:

> Actually it would be nice to be able to convert:
>
>!any string
>
> to:
>
> <h1>any string</h1>
>
> as well. So "any string" can be ... ehm any string and the ! should be
> converted to <h1> at the beginning of the line and </h1> at the end.


t = t.replace(/^!(.*)/,'<h1>$1</h1>')

Next time first try it yourself.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
 
Reply With Quote
 
scriptguru@gmail.com
Guest
Posts: n/a
 
      09-10-2006

Thomas Ardal написав:
> Actually it would be nice to be able to convert:
>
> !any string
>
> to:
>
> <h1>any string</h1>
>
> as well. So "any string" can be ... ehm any string and the ! should be
> converted to <h1> at the beginning of the line and </h1> at the end.
>
> Regards,
> Thomas

str=str.replace(/\!([^\n\r])+/g,'<h1>$1</h1>')

 
Reply With Quote
 
Danny
Guest
Posts: n/a
 
      09-10-2006


Well
'!any string here'.replace(/^([^$]+)$/g, '<h1> $1 <\/h1>');


Danny
 
Reply With Quote
 
Evertjan.
Guest
Posts: n/a
 
      09-11-2006
Danny wrote on 11 sep 2006 in comp.lang.javascript:

> Well
> '!any string here'.replace(/^([^$]+)$/g, '<h1> $1 <\/h1>');


Two problems:

1 you did not quote, which on usenet is a sin, as we won't know what you
are reacting upon.

2 why the extra spaces and not just '<h1>$1<\/h1>'

3 why the /g here?

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
 
Reply With Quote
 
Evertjan.
Guest
Posts: n/a
 
      09-11-2006
Evertjan. wrote on 11 sep 2006 in comp.lang.javascript:

> Danny wrote on 11 sep 2006 in comp.lang.javascript:
>
>> Well
>> '!any string here'.replace(/^([^$]+)$/g, '<h1> $1 <\/h1>');

>
> Two problems:
>
> 1 you did not quote, which on usenet is a sin, as we won't know what you
> are reacting upon.
>
> 2 why the extra spaces and not just '<h1>$1<\/h1>'
>
> 3 why the /g here?
>


4 I cannot count!

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Seek xpath expression where an attribute name is a regular expression GIMME XML 3 12-29-2008 03:11 PM
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" Adem C++ 42 11-04-2008 12:39 PM
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" Adem C Programming 45 11-04-2008 12:39 PM
Matching abitrary expression in a regular expression =?iso-8859-1?B?bW9vcJk=?= Java 8 12-02-2005 12:51 AM
Dynamically changing the regular expression of Regular Expression validator VSK ASP .Net 2 08-24-2003 02:47 PM



Advertisments