473,408 Members | 1,840 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,408 software developers and data experts.

Regular expression from JavaScript

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
Sep 10 '06 #1
6 1042
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 <h1at the beginning of the line and </h1at the end.

Regards,
Thomas
Sep 10 '06 #2
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 <h1at the beginning of the line and </h1at 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)
Sep 10 '06 #3

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 <h1at the beginning of the line and </h1at the end.

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

Sep 10 '06 #4


Well
'!any string here'.replace(/^([^$]+)$/g, '<h1$1 <\/h1>');
Danny
Sep 10 '06 #5
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)
Sep 11 '06 #6
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)
Sep 11 '06 #7

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

Similar topics

8
by: Rajeev Soni | last post by:
Hi I am looking for the regular expression for validating the allowed file types to upload like files like "zip,pdf,doc,rtf,gif,jpg,png,txt"; and the expression should not be case sensitive like...
2
by: Dot net work | last post by:
Hello. Say I have a .net textbox that uses a .net regularexpressionvalidator. If the regular expression fails, is it possible to launch a small client side javascript function to do something,...
18
by: Q. John Chen | last post by:
I have Vidation Controls First One: Simple exluce certain special characters: say no a or b or c in the string: * Second One: I required date be entered in "MM/DD/YYYY" format: //+4 How...
3
by: Lisa Bogart | last post by:
I am trying to take a string and parse it out into multiple strings based on a pattern but am stuck and am hoping someone can give me a clue. My pattern looks like so: sMatch =...
1
by: Stan | last post by:
I have a very simple web form with a textbox and a regular expression validator. The regular expression I'm attempting to use doesn't work on the client side (Javascript) tho it works on the server...
1
by: Allan Ebdrup | last post by:
I have a dynamic list of regular expressions, the expressions don't change very often but they can change. And I have a single string that I want to match the regular expressions against and find...
3
by: Mr.Steskal | last post by:
Posted: Wed Jul 11, 2007 7:01 am Post subject: Regular Expression Help -------------------------------------------------------------------------------- I need help writing a regular...
12
by: FAQEditor | last post by:
Anybody have any URL's to tutorials and/or references for Regular Expressions? The four I have so far are: http://docs.sun.com/source/816-6408-10/regexp.htm...
12
by: joey.powell | last post by:
Hello guys, I am primarily an asp.net programmer, but lately I've been doing some work with Apache, MySQL and PHP. Anyways, I have a question that I posted in the microsoft asp.net newsgroup....
1
by: NvrBst | last post by:
I want to use the .replace() method with the regular expression /^ %VAR % =,($|&)/. The following DOESN'T replace the "^default.aspx=,($|&)" regular expression with "":...
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.