This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

How to catch all numbers in a string ???

Old posts that have not been replied to for several years.
Locked
F
Friischling

How to catch all numbers in a string ???

Post by Friischling »

Hey there

I need some code, which cathes all numbers in a string.
eg.

!guess kl232 sai0d

should give med 232 and 0
Any ideas ?

// JF
User avatar
Papillon
Owner
Posts: 724
Joined: Fri Feb 15, 2002 8:00 pm
Location: *.no

Post by Papillon »

this should do the trick

Code: Select all

regsub -all {[^0-9]} $text {} newtext
Elen sila lúmenn' omentielvo
F
Friischling

Post by Friischling »

Thx alot - it works like a dream
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Post by awyeah »

Also you can use regular expressions for the same thing.

Code: Select all

    set countnumbers [regexp -all {[0-9]} $text]
The variable $countnumbers will be a value of the counted
numbers in the text.

Take a look at this previous thread and the examples
you can get an idea.

http://forum.egghelp.org/viewtopic.php?t=7451
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
e
egghead
Master
Posts: 481
Joined: Mon Oct 29, 2001 8:00 pm
Contact:

Post by egghead »

awyeah wrote:Also you can use regular expressions for the same thing.

Code: Select all

    set countnumbers [regexp -all {[0-9]} $text]
The variable $countnumbers will be a value of the counted
numbers in the text.
[snip]
That's not what Friischling asked for.
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

regexp = match a regular expression against a string
regsub = perform substitutions based on regular expression pattern matching
Once the game is over, the king and the pawn go back in the same box.
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Post by awyeah »

Yeah sorry, that code I gave was to count
the numbers in a text, and place the total value
of numbers in a variable.

However, the link I supplied for reference and examples
is correct, and you can get an idea from that.
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Who said that the code you have pasted is not correct? It is but is not what Friischling was looking for.
Once the game is over, the king and the pawn go back in the same box.
Locked