Is there any reason why RegExp wouldn't be able to find a period?
str = '256.89';
a = new RegExp('(\.)');
b = /(\.)/;
alert(str.repla ce(a, 'x$1x'));
alert(str.repla ce(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. 3 3239
On 15 Jan 2004 01:01:23 -0800, tr**********@ya hoo.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.repl ace(a, 'x$1x')); alert(str.repl ace(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
On Thu, 15 Jan 2004 11:14:05 GMT, Steve van Dongen
<st*****@hotmai l.com> wrote: On 15 Jan 2004 01:01:23 -0800, tr**********@ya hoo.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
Steve van Dongen <st*****@hotmai l.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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 what's wrong. Another little
email check works fine, using the code out of Wrox' Beginning PHP.
PhoneCheck.php
<?php
function PhoneCheck($number)
{
return ereg("^?\d{3} ]*\d{3}?\d{4}$", $number,
|
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:
domything()
And the regexp search assuming no case restriction would be,
|
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.
Or how can I replace the html &entities; in a string
"blablabla&blablabal&balbalbal" with the chars they mean using
re.sub? I found out they are stored in an dict . I though about this functionality:
|
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 not appear to work:
var email_address = "Joe@Schmoe";
var email_regex = new RegExp ("^(\\w+)(\@)(\\w+)(\.)(\\w+)$");
var result = email_regex.exec (email_address);
alert (" result = \"" + result + "\"\n" +
" result = \"" + result + "\"\n" +
"...
|
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 and isNaN, but
I'm not even sure that the results are as perfect as I need. I am
expecting to use RegExp.test(string), but I'm not 100% sure about that,
either.
Here is a test program with a textbox that has a maxlength of 2
characters. The...
| |
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 whatever I do gets errors. The examples use
namespace regExp, but the supplied files use regexp, I've got it so that
it at least doesn't complain about namespaces but it then complains that
it can't find the match function. My stylesheet is:
|
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 price of a stock. The program will allow users to query the stock price of a
particular date and output its statistics (mean price, median price and standard deviation) for any
specified period. Your program must be menu driven and works as follows.
|
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("+");
var testing4=new RegExp("{1,}");
window.alert(testing1.test("ab")+"\n"+testing2.test("ab")+"\n"+testing3.test("ab")+"\n"+testing4.test("ab"));}When this script is run, the window.alert contains the following results:truetruefalsefalseThe the first...
|
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' is not an appropriate
modifier for the test() function - test() searches the entire string
by default.
However, I would expect it to degrade gracefully. Instead, I seem to
be getting something as follows - using W3Schools handy page at :
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |