I want to search a textbox and replace any instances of the dollar sign
character. But when I do that it thinks it won't work because it think's I'm
looking to replace something at the end of the line. How do I tell it to
look for literal dollar signs? 10 12067
Terry Olson wrote: I want to search a textbox and replace any instances of the dollar sign character. But when I do that it thinks it won't work because it think's I'm looking to replace something at the end of the line.
What is 'it'?
Some mysterycode we can only guess about?
How do I tell it to look for literal dollar signs?
2 things that pop into mind:
1) use String.substring() in combination with indexOf() and some basic
coding.
2) Or a regular expression which is probably more complex to understand for
starters.
I would advise you to do it with the first option.
Good luck.
Erwin Moller
I am using Regular Expressions, I tried putting just a simple \ in front of
it; as in /\$/g and that seems to work, anyone got a better idea?
"Erwin Moller"
<si******************************************@spam yourself.com> wrote in
message news:41***********************@news.xs4all.nl... Terry Olson wrote:
I want to search a textbox and replace any instances of the dollar sign character. But when I do that it thinks it won't work because it think's I'm looking to replace something at the end of the line. What is 'it'? Some mysterycode we can only guess about?
How do I tell it to look for literal dollar signs?
2 things that pop into mind: 1) use String.substring() in combination with indexOf() and some basic coding. 2) Or a regular expression which is probably more complex to understand
for starters. I would advise you to do it with the first option.
Good luck.
Erwin Moller
On Tue, 07 Sep 2004 08:27:11 GMT, Terry Olson <tw******@hotmail.com> wrote: I am using Regular Expressions, I tried putting just a simple \ in front of it; as in /\$/g and that seems to work, anyone got a better idea?
That *is* how to do it. The only way, in fact. :)
Mike
Please don't top-post.
--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Michael Winter wrote: On Tue, 07 Sep 2004 08:27:11 GMT, Terry Olson <tw******@hotmail.com> wrote:
I am using Regular Expressions, I tried putting just a simple \ in front of it; as in /\$/g and that seems to work, anyone got a better idea?
That *is* how to do it. The only way, in fact. :)
Mike
Please don't top-post.
This works fine for me:
$str1 = '$Hello! All the dollars $ should $ be replaced by $ **';
$str2 = ereg_replace ( '\$', '**', $str1);
echo "str1= $str1<br>";
echo "str2= $str2<br>";
Erwin Moller wrote: Michael Winter wrote:
On Tue, 07 Sep 2004 08:27:11 GMT, Terry Olson <tw******@hotmail.com> wrote:
I am using Regular Expressions, I tried putting just a simple \ in front of it; as in /\$/g and that seems to work, anyone got a better idea?
That *is* how to do it. The only way, in fact. :)
Mike
Please don't top-post.
This works fine for me:
$str1 = '$Hello! All the dollars $ should $ be replaced by $ **'; $str2 = ereg_replace ( '\$', '**', $str1);
echo "str1= $str1<br>"; echo "str2= $str2<br>";
Oops, sorry, that was PHP of course. :-)
Excuse me.
On Tue, 07 Sep 2004 12:30:30 +0200, Erwin Moller
<si******************************************@spam yourself.com> wrote: Michael Winter wrote:
On Tue, 07 Sep 2004 08:27:11 GMT, Terry Olson <tw******@hotmail.com> wrote:
I am using Regular Expressions, I tried putting just a simple \ in front of it; as in /\$/g and that seems to work, anyone got a better idea? That *is* how to do it. The only way, in fact. :)
[snip]
$str1 = '$Hello! All the dollars $ should $ be replaced by $ **'; $str2 = ereg_replace ( '\$', '**', $str1);
If converted to Javascript, you don't need the backslash with the string
argument form of the replace method. In that instance, it's a simple
string comparison. If you are using a regular expression, then the
backslash is necessary to ensure the ampersand isn't interpreted as a
special character. This latter case is what I was referring to. So
initially, your two options are:
var str = '$Hello! All the dollars $ should $ be replaced by $ **',
res;
res = str.replace('$', '**');
or
res = str.replace(/\$/, '**');
However, both of these should only replace the first instance of an
ampersand. If all occurances need to be replaced, you have to use regular
expression the OP presented:
res = str.replace(/\$/g, '**');
Mike
--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Michael Winter wrote on 07 sep 2004 in comp.lang.javascript : res = str.replace(/\$/, '**');
However, both of these should only replace the first instance of an ampersand. If all occurances need to be replaced, you have to use regular expression the OP presented:
I know the $ is devaluating, but has it become an & ?
;-}
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress,
but let us keep the discussions in the newsgroup)
On 07 Sep 2004 13:10:09 GMT, Evertjan. <ex**************@interxnl.net>
wrote: Michael Winter wrote on 07 sep 2004 in comp.lang.javascript:
res = str.replace(/\$/, '**');
However, both of these should only replace the first instance of an ampersand. If all occurances need to be replaced, you have to use regular expression the OP presented:
I know the $ is devaluating, but has it become an & ?
;-}
:P
Hmm. Yes, I meant a dollar symbol rather than an ampersand.
Mike
--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
JRS: In article <opsdx7e9d6x13kvk@atlantis>, dated Tue, 7 Sep 2004
08:33:02, seen in news:comp.lang.javascript, Michael Winter <M.Winter@bl
ueyonder.co.invalid> posted : On Tue, 07 Sep 2004 08:27:11 GMT, Terry Olson <tw******@hotmail.com> wrote:
I am using Regular Expressions, I tried putting just a simple \ in front of it; as in /\$/g and that seems to work, anyone got a better idea?
That *is* how to do it. The only way, in fact. :)
x = "34$56".replace(/\x24/, '#')
x = "34$56".replace(/\044/, '#')
x = "34$56".replace(/\u0024/, '#')
x = "34$56".replace(/[^\000-#%-\377]/, '#')
all give me "34#56".
By "only", you must mean "proper" or "best" rather than "unique".
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms & links;
some Astro stuff via astro.htm, gravity0.htm; quotes.htm; pascal.htm; &c, &c.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
On Tue, 7 Sep 2004 20:42:42 +0100, Dr John Stockton
<sp**@merlyn.demon.co.uk> wrote: JRS: In article <opsdx7e9d6x13kvk@atlantis>, dated Tue, 7 Sep 2004 08:33:02, seen in news:comp.lang.javascript, Michael Winter <M.******@blueyonder.co.invalid> posted : On Tue, 07 Sep 2004 08:27:11 GMT, Terry Olson <tw******@hotmail.com> wrote:
I am using Regular Expressions, I tried putting just a simple \ in front of it; as in /\$/g and that seems to work, anyone got a better idea?
That *is* how to do it. The only way, in fact. :)
x = "34$56".replace(/\x24/, '#') x = "34$56".replace(/\044/, '#') x = "34$56".replace(/\u0024/, '#') x = "34$56".replace(/[^\000-#%-\377]/, '#')
all give me "34#56".
By "only", you must mean "proper" or "best" rather than "unique".
The OP wanted to know if the backslash was necessary. I took that to mean,
"Is escaping necessary?". My reply was yes.
I must admit, I hadn't considered the last approach, but I think that
one's just a little over-the-top. :)
Mike
--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: andreas kirschner |
last post by:
hello regexp developers,
how can i replace text outside a html syntax by using reg exps in php?
I mean i have a text like
<h3>heading</h3>
<p>text</p>
<table>
<tr>
<td>cell1</td>
|
by: Svennglenn |
last post by:
I'm having problems replacing text in a
unicode string.
Here's the code:
# -*- coding: cp1252 -*-
titel = unicode("ä", "iso-8859-1")
print titel
print type(titel)
|
by: michael |
last post by:
What methods (eg. CSS/Javascript) are there to dynamically replace text
other than dynamically changing form text field values?
I don't mean color styles and fonts etc., but actual text content...
|
by: spence |
last post by:
Hi All
How do I make it so that when a user clicks in a search text field, the
default entry (in this case "Search") is removed automatically - they
are then faced with a blank search box and...
|
by: Andla Rand |
last post by:
Hi,
I would appreciate some directions on how to replace text as server
controls. I'm currently reading text from a database and would like to
build server logic based on specific information...
|
by: Casey |
last post by:
Hello,
Can someone give me specific code to replace text on a page using
server side javascript? I need to use server-side because I need the
output to be recognized in the final HTML so that...
|
by: shantibhushan |
last post by:
Hi buddy
I have to highlight search text from search results as it is in google or alibaba.com.
e.g. if I input paper as a searchtext in search results paper word should be highlighted. as it...
|
by: Ivica Muruzovic |
last post by:
How can I use previous typed search text in google search box or any
other web browser. I have combobox and want to fill him with that
previous typed search text on local machine
|
by: fosforito |
last post by:
How can you replace text in batch mode (that is, a large text with many entries of that kind)?
For example: Look for "http://microsoft.com/serverads/" and replace it for...
|
by: sangam56 |
last post by:
Hi all.
I have an iframe in an asp.net web page (Display.aspx).
<iframe id="iframe1" runat="server" src="temp/test.html"></iframe>
Now I need to highlight a search text, say 'test' in the...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
| |