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

Regex help - probably an easy one for an expert.

DbZ
Hi - i'm new to the regex thing - and trying to learn it to myself -
Can someone please explain to me what the following line does -
value.replace(/\s+$/g,"")

I can kinda figure out its replacing a something with an empty space -
on a global search. But thats about it

Thanks for your help
DBZ

Aug 7 '07 #1
5 1394
DbZ wrote on 07 aug 2007 in comp.lang.javascript:
Hi - i'm new to the regex thing - and trying to learn it to myself -
Can someone please explain to me what the following line does -
value.replace(/\s+$/g,"")
Please read the NG FAQ entry.
<http://www.jibbering.com/faq/#FAQ4_16>

However your string is not made by an expert,
because using the global flag "g" makes no sense,
when specifying the end of string "$" in the regex string.
I can kinda figure out its replacing a something with an empty space -
on a global search. But thats about it
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Aug 7 '07 #2
In article <11**********************@19g2000hsx.googlegroups. com>,
DbZ <de**********@gmail.comwrote:
Hi - i'm new to the regex thing - and trying to learn it to myself -
Can someone please explain to me what the following line does -
value.replace(/\s+$/g,"")

I can kinda figure out its replacing a something with an empty space -
on a global search. But thats about it
My advice is to steer clear of regex as much as you possibly can,
because anything more complex than the most simple examples are
incomprehensible about 5 mins after you last understood it.
Aug 7 '07 #3
Tim Streater wrote on 07 aug 2007 in comp.lang.javascript:
My advice is to steer clear of regex as much as you possibly can,
because anything more complex than the most simple examples are
incomprehensible about 5 mins after you last understood it.
Bad advice, Tim.

As well as being terribly handy and enjoyable,
writing Regex is an important antidote
to Alzheimer progression.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Aug 7 '07 #4
DbZ wrote:
Hi - i'm new to the regex thing - and trying to learn it to myself -
I can very much recommend reading the two free sample chapters of Mastering
Regular Expressions First and Second Edition by Jeffrey E. F. Friedl at
O'Reilly Online. And probably the book is worth buying.

http://www.oreilly.com/catalog/regex/ pp.
Can someone please explain to me what the following line does -
value.replace(/\s+$/g,"")

I can kinda figure out its replacing a something with an empty space -
on a global search. But thats about it
It is replacing one or more consecutive (`+') whitespace (`\s') at the end
(`$') of the string `value' with the empty string (`""', i.e. removing the
matched substring) and returns the result. (The `g'lobal flag which would
make the expression to apply to *every* match, not only the first one, is
therefore unnecessary here; there can be only one match because the
expression is anchored by `$'.)

For the above to have effect, you would need to assign the result to
something, for example:

value = value.replace(/\s+$/, "");
HTH

PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f8*******************@news.demon.co.uk>
Aug 7 '07 #5
Dr J R Stockton wrote on 07 aug 2007 in comp.lang.javascript:
>>As well as being terribly handy and enjoyable,
writing Regex is an important antidote
to Alzheimer progression.

No : it does not make you keep your wits as you get much older, it
merely makes you feel much older while retaining the earlier wits, if
any.
John, you are pesimistic about the "use it or lose it" potential,

It is not decided yet.

Mental exercise [in the Morris water maze] really seems to have more than a
placebo effect:
"Voluntary Exercise Decreases Amyloid Load in a Transgenic Model of
Alzheimer's Disease" [The Journal of Neuroscience, April 27, 2005, 25
(17):4217-4221;]
<http://www.jneurosci.org/cgi/content/short/25/17/4217>

On the other hand:

Commentary: Activity each day keeps dementia away —
does social interaction really preserve cognitive function?
<http://ije.oxfordjournals.org/cgi/reprint/34/4/872>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Aug 7 '07 #6

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

Similar topics

8
by: Johnny | last post by:
I need to determine whether a text box contains a value that does not convert to a decimal. If the value does not convert to a decimal, I want to throw a MessageBox to have the user correct the...
7
by: bill tie | last post by:
I'd appreciate it if you could advise. 1. How do I replace "\" (backslash) with anything? 2. Suppose I want to replace (a) every occurrence of characters "a", "b", "c", "d" with "x", (b)...
7
by: Razzie | last post by:
Hey all, Decided to give a shot at Regular expressions - need a bit of help :) I can't seem to find the right regex for matching words like "*test*" or *somevalue*" - in short, all words...
3
by: Luis Esteban Valencia | last post by:
hello quite a simple one if you understand regular expressions vbscript and ..net, probably quite hard if you don't i have a single line input which offers classic search functionality, so if...
17
by: clintonG | last post by:
I'm using an .aspx tool I found at but as nice as the interface is I think I need to consider using others. Some can generate C# I understand. Your preferences please... <%= Clinton Gallagher ...
6
by: PaulM | last post by:
...all but the first x chars in a string of arbitrary length? Apologies if this is the wrong forum; I wasn't sure the best place to post about Regex. Background: I am new to Regex for pattern...
2
by: Smokey Grindel | last post by:
I have an app that builds where clauses (its 3rd party) and for some reason it adds an m after decimal numbers... so I get results like this = 45.1234m And Like '123%' And = '45.1234m' ...
4
by: seberino | last post by:
I'm looking over the docs for the re module and can't find how to "NOT" an entire regex. For example..... How make regex that means "contains regex#1 but NOT regex#2" ? Chris
31
by: raylopez99 | last post by:
I went through a bunch of Regex examples, and indeed it's quite powerful, including 'groups' using 'matches', word boundaries, lookahead matches, replacing and splitting text,etc--apparently...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
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...

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.