Hi,
I'trying to use a regExp in Javascript to replace any all upper case word in a string by the same word having only its first letter in upper case.
This expression detects the words:
/([A-ZÄÀÉÈÊËÎÏÔÙÛÜ])([A-ZÄÀÉÈÊËÎÏÔÙÛÜ]+)/g
and backreferences $1 and $2 will contain the first letter and the rest of the word respectively.
Now, how can I convert $2 to lower case in the replace function?
I would need something like:
replace(/([A-ZÄÀÉÈÊËÎÏÔÙÛÜ])([A-ZÄÀÉÈÊËÎÏÔÙÛÜ]+)/g, "$1" + "$2".toLowerCas e())
But this does not work since the toLowerCase() is applied first to the string "$2", THEN the string $2 is replaced by the second match. 3 3613
Claude Schneegans wrote: Now, how can I convert $2 to lower case in the replace function? I would need something like: replace(/([A-ZÄÀÉÈÊËÎÏÔÙÛÜ])([A-ZÄÀÉÈÊËÎÏÔÙÛÜ]+)/g, "$1" + "$2".toLowerCas e()) But this does not work since the toLowerCase() is applied first to the string "$2", THEN the string $2 is replaced by the second match.
Try:
var s = "ABCDE FGHI";
s = s.replace(
/([A-ZÄÀÉÈÊËÎÏÔÙÛÜ]+)/g,
function (w) {
return w.charAt(0).toU pperCase() +
w.substring(1). toLowerCase();
}
);
alert(s);
HTH;
JW
Claude Schneegans a ecrit : Hi,
I'trying to use a regExp in Javascript to replace any all upper case word in a string by the same word having only its first letter in upper case. This expression detects the words: /([A-ZÄÀÉÈÊËÎÏÔÙÛÜ])([A-ZÄÀÉÈÊËÎÏÔÙÛÜ]+)/g and backreferences $1 and $2 will contain the first letter and the rest of the word respectively.
truc=truc.charA t(0).toUpperCas e()+truc.substr ing(1,truc.leng th).toLowerCase ; Now, how can I convert $2 to lower case in the replace function?
$something is not accepted in JS language !
--
******** (enlever/remove [OTER_MOI] du/from reply url) *******
Stéphane MORIAUX : mailto:st****** *************** @wanadoo.fr
Aide aux Pages Perso (images & couleurs, formulaire, CHP, JS) http://perso.wanadoo.fr/stephane.moriaux/internet/
*************** *************** *************** *************** **
"@SM" <st************ *********@wanad oo.fr> writes: $something is not accepted in JS language !
Is so! :P
Javascript identifiers may contains the letters (a-z, any case),
digits (0-9), underscore (_) and dollar sign ($). The first character
may not be a digit. Read ECMA 262, section 7.6.
The $ is *intended* for mechanically generated code, but there is no
requirements.
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.' This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Hallvard B Furuseth |
last post by:
Has someone got a Python routine or module which converts Unicode
strings to lowercase (or uppercase)?
What I actually need to do is to compare a number of strings in a
case-insensitive manner, so I assume it's simplest to convert to
lower/upper first.
Possibly all strings will be from the latin-1 character set, so I could
convert to 8-bit latin-1, map to lowercase, and convert back, but that
seems rather cumbersome.
|
by: DJ |
last post by:
Can someone tell me the library call that converts strings to lower case or
retrns a new string that is lower case of the original, thanks
im using <string>
David
|
by: Janice |
last post by:
char* line = "abcd";
How to convert the line to upper case and print?
Any option for printf to do this?
Thanx
|
by: Peter Oliphant |
last post by:
I've been trying all morning to convert my 2003 project (managed) to 2005
(/clr since I have both managed and unmanaged code). I'm guessing I have
tens of thousands of lines of code to change. Did a lot of converting '__gc'
to 'ref', converting '*' to '^', converting 'new' to 'gcnew'. Of course this
can't be done with a blanket replace, as my code has both managed and
unmanaged segments. Thus I have to do them one-by-one. Also, things are...
|
by: Eric Lindsay |
last post by:
Should HTML 4.01 Strict markup be done in upper case or in lower case?
I understand that HTML allows either upper or lower case. I also notice
that XHTML apparently requires lower case. However I saw some mention
that the HTML DOM uses upper case for markup elements.
So, should I worry about what this means?
I am inclined to go with lower case, for two reasons.
Easier to change if I subsequently want to use XHTML.
| |
by: n33470 |
last post by:
We have a web site that is being converted from the 1.1 format into
2.0. I've noticed that after the web project has been converted, the
first time that the solution is opened in VS, all of the aspx and ascx
filenames are changed to lowercase.
The filenames are not being changed during the conversion process.
After conversion completes, the filenames remain unchanged. However,
the first time that the solution is opened in VS2005, the...
|
by: bob |
last post by:
In vb6 you could say s = Format(s, "!") to force text to upper case in
the format
function. I've searched the vb.net help system and can't find any help
on formatting text. There's plenty of help formatting numbers, dates,
and times, though.
Does the vb.net format function have a way to convert text to upper or
lower case?
Thanks.
|
by: B Williams |
last post by:
I have written some code that will take in a string and print out the
reverse, but I also want it to check for upper and lower case and swap them.
Will someone assist me?
include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include <string>
|
by: Curious |
last post by:
I'm working on a word replacement program in .NET. I have a list of
words spelt in American English and need to replace them with
translated British spelling while keeping the upper or lower cases of
each letter in these words.
For instance, I have a dictionary below:
theater theatre
center centre
annualized annualised
|
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: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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: 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: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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.
| |