473,385 Members | 1,372 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 can't find a period

Is there any reason why RegExp wouldn't be able to find a period?

str = '256.89';
a = new RegExp('(\.)');
b = /(\.)/;
alert(str.replace(a, 'x$1x'));
alert(str.replace(b, 'x$1x'));

The alert for a says
x2x56.89

However the alert for b says
256x.x89

b is the result I want, because it means that the period was found. a
is just finding a single character, as if it's ignoring the escape in
front of the period.

I've tried this in IE and Mozilla.
Jul 20 '05 #1
3 3212
On 15 Jan 2004 01:01:23 -0800, tr**********@yahoo.com (trialofmiles)
wrote:
Is there any reason why RegExp wouldn't be able to find a period?

str = '256.89';
a = new RegExp('(\.)');
Here's a hint:
When used in a STRING, the backslash is the escape character.
b = /(\.)/;
alert(str.replace(a, 'x$1x'));
alert(str.replace(b, 'x$1x'));

The alert for a says
x2x56.89

However the alert for b says
256x.x89

b is the result I want, because it means that the period was found. a
is just finding a single character, as if it's ignoring the escape in
front of the period.

I've tried this in IE and Mozilla.


Regards,
Steve
Jul 20 '05 #2
On Thu, 15 Jan 2004 11:14:05 GMT, Steve van Dongen
<st*****@hotmail.com> wrote:
On 15 Jan 2004 01:01:23 -0800, tr**********@yahoo.com (trialofmiles)
wrote:
Is there any reason why RegExp wouldn't be able to find a period?

str = '256.89';
a = new RegExp('(\.)');


Here's a hint:
When used in a STRING, the backslash is the escape character.


Yeah, what you actually need to do is:

a = new RegExp('(\\.)');

when its a string.

hth
Al
Jul 20 '05 #3
Steve van Dongen <st*****@hotmail.com> wrote in message news:<hc********************************@4ax.com>. ..
Here's a hint:
When used in a STRING, the backslash is the escape character.


Sometimes the solution is so simple. Thank you very much.

What's strange is at one point I had written it \\. and things weren't
working the way I expected. But that was when I was trying it as part
of a larger regular expression. Another piece of the expression must
have been wrong. Things are working now.
Jul 20 '05 #4

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

Similar topics

8
by: Greg Bryant | last post by:
I'm working on validating US phone numbers. I have a nice expression that Regex Coach likes, but causes PHP to reject everything I send. Are there any glaring differences? I can't figure out...
10
by: Anand Pillai | last post by:
To search a word in a group of words, say a paragraph or a web page, would a string search or a regexp search be faster? The string search would of course be, if str.find(substr) != -1:...
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....
10
by: Andrew DeFaria | last post by:
I was reading my O'Reilly JavaScript The Definitive Guide when I came across RegExp and thought I could tighten up my JavaScript code that checks for a valid email address. Why does the following...
10
by: Jeff Sandler | last post by:
I have a page that accepts input from many textboxes. Many of the textboxes are intended to accept dates and times, thus, I expect only digits to be entered. I originally tested using parseInt...
0
by: Chris Croughton | last post by:
I'm trying to use the EXSLT regexp package from http://www.exslt.org/regexp/functions/match/index.html (specifically the match function) with the libxml xltproc (which supports EXSLT), but...
0
by: georges the man | last post by:
The purpose: • Sorting and Searching • Numerical Analysis Design Specification You are to write a program called “StockAnalyser”. Your program will read a text file that contains historical...
2
by: Nathan Sokalski | last post by:
I have the following script that I am using to test some JavaScript RegExp code: function RE() { var testing1=new RegExp("*"); var testing2=new RegExp("{0,}"); var testing3=new RegExp("+");...
4
by: Matt | last post by:
Hello all, I have just discovered (the long way) that using a RegExp object with the 'global' flag set produces inconsistent results when its test() method is executed. I realize that 'global'...
1
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...
0
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...
0
isladogs
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...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.