[Question]
  [
# Winner: [Chilemagic](https://codegolf.stackexchange.com/a/37113/10961), a massive 21 bytes!
You may continue to submit your answer, however you can no longer win. Original post kept:
---
Your goal is to find all numbers in a string, and multiply each one individually by a value input by the user
* You will not need to worry about decimals
* The user will input a number and a string
* The user must type the number and string at some point, **however** the method the program reads it does not matter. It can be with stdin, reading a text file, etc, however the user must press the 9 button on their keyboard (for example) at some point
* Anything that can compile and run is acceptable
# Example:
Sentence input: This 1 is22a 3352sentence 50
Number input: 3
Output: This 3 is66a 10056sentence 150
---
* This contest ends on September 6th, 2014 (7 days from posting).
* This is a [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest code wins
  
[Answer]
## Update - Perl - 17
```
s/\d+/$&*$^I/ge
```
15 characters + 2 for `-i` and `-p` flags.
We can use the `-i` flag to input a file extension, but since we aren't reading any files, we can use it to get the number and it the variable `$^I` will get assigned to it.
Run with:
```
perl -e'print"This 1 is22a 3352sentence 50"' | perl -i3 -pe's/\d+/$&*$^I/ge'
```
## Perl - 21
Updated as per @Dennis's comment.
```
$n=<>;s/\d+/$&*$n/ge
```
Run with `-p` flag.
## Example run:
```
perl -e'print"This 1 is22a 3352sentence 50\n3"' | perl -pe'$n=<>;s/\d+/$&*$n/ge'
```
## Explanation:
`$n=<>;` read in the number
`-p` prints the output
`s/\d+/$&*$n/ge` Read the input with <> and search for one or more digits and replace them with the digits times the number. `g` is global, `e` is `eval` the replace potion of the s///. `$&` contains what was matched and it multiplied by the number, `$n`.
You can read more about `s///` in [perlop](http://perldoc.perl.org/perlop.html#Regexp-Quote-Like-Operators) and more about Perl regexes in [perlre](http://perldoc.perl.org/perlre.html).
## Another solution:
@F.Hauri pointed out you can also use the `s` [switch](http://perldoc.perl.org/perlrun.html#Command-Switches) to assign the `$n` variable to 4. I'm not sure how many characters this counts as but I'll leave it here:
```
perl -spe 's/\d+/$&*$n/ge' -- -n=4 <<<'This 1 is22a 3352sentence 50'
```
[Answer]
# JavaScript (ES6) - ~~48~~ 44 chars
Thanks to [@bebe](https://codegolf.stackexchange.com/questions/37110/multiply-all-numbers-in-a-string/37127?noredirect=1#comment83985_37127) for saving one character. Update: 8/Mar/16, removed another four characters
```
b=(p=prompt)();p(p().replace(/\d+/g,y=>y*b))
```
**Ungolfed**:
```
var sentence = prompt(),
    num = parseInt(prompt(), 10); // base 10
sentence = sentence.replace(/\d+/g, digit => digit * num);
alert(sentence);
```
### 43 chars:
```
(p=prompt)(p(b=p()).replace(/\d+/g,y=>y*b))
```
```
b=(p=prompt)();p(p().replace(/\d+/g,y=>y*b))
```
Requires number input first and then sentence.
Cut one char more here thanks @bebe again!
[Answer]
## Python 2 (79)
```
import re
n=input()
s=input()
print re.sub('\d+',lambda x:`int(x.group())*n`,s)
```
### Sample run
Input:
```
$ python mult.py
3
"This 1 is22a 3352sentence 50"
```
Output:
```
This 3 is66a 10056sentence 150
```
Online demo: <http://ideone.com/V6jpyQ>
[Answer]
# Python 2 - 126
```
import re
n=input()
s=input()
for i in list(re.finditer('\d+',s))[::-1]:s=s[:i.start()]+`int(i.group())*n`+s[i.end():]
print s
```
First input: integer `n`.
Second input: string `s` (with quotation marks, e.g. `"abc42"`).
[Answer]
# CJam, ~~47~~ ~~33~~ 30 bytes
```
q_A,sNerN%\[_A,s-Ner~](f*]zs1>
```
Reads the number and the string (in that order and separated by a single space) from STDIN.
[Try it online.](http://cjam.aditsu.net/ "CJam interpreter")
### Example run
```
$ cjam multiply.cjam <<< '7 N0 R3GUL4R 3XPR35510N5 1N CJ4M M4K3 M3 4 54D P4ND4'
N0 R21GUL28R 21XPR248570N35 7N CJ28M M28K21 M21 28 378D P28ND28
```
### How it works
```
q                                 " Read from STDIN (“Q”) and push a second copy.         ";
  A,s                             " Push “0123456789” (thanks, @aditsu).                  ";
 _   NerN%                        " Replace digits with linefeeds and split at linefeeds. ";
          \ _A,s-Ner              " Replace non-digits with linefeeds.                    ";
                    ~             " Evaluate the resulting string.                        ";
           [         ]            " Collect the results in an array.                      ";
                      (f*         " Multiply all other integers by the first.             ";
                         ]z       " Interleave the elements of both arrays.               ";
                           s1>    " Flatten the result and discard the leading space.     ";
```
[Answer]
# Bash+coreutils, 38 bytes
```
eval echo `sed "s/[0-9]\+/$\[$1*&]/g"`
```
Reads input string from STDIN and multiplier as a command-line parameter.
### Output:
```
$ ./multstr.sh 3 <<< "This 1 is22a 3352sentence 50"
This 3 is66a 10056sentence 150
$ 
```
[Answer]
# C# in LINQPad, 124
Straightforward. Please use **CTRL+2** in LINQPad (Language: C# Statements).
```
var s=Console.ReadLine();var k=int.Parse(Console.ReadLine());new Regex("\\d+").Replace(s,t=>""+int.Parse(t.Value)*k).Dump();
```
If the multiplier is given as first input parameter, it can be done in 116 characters:
```
var k=int.Parse(Console.ReadLine());new Regex("\\d+").Replace(Console.ReadLine(),t=>""+int.Parse(t.Value)*k).Dump();
```
---
**EDIT:**
Thanks to Abbas's comment below, this can even be golfed more by using [Regex static method](http://msdn.microsoft.com/en-us/library/e7f5w83z(v=vs.110).aspx), rather than instantiate it:
```
var k=int.Parse(Console.ReadLine());Regex.Replace(Console.ReadLine(),"\\d+",t=>""+int‌​.Parse(t.Value)*k).Dump();
```
[Answer]
# Cobra - 171
```
use System.Text.RegularExpressions
class P
    def main
        a=int.parse(Console.readLine?'')
        print Regex.replace(Console.readLine,'\d+',do(m as Match)="[int.parse('[m]')*a]")
```
[Answer]
# Python 3 - 141
I don't think I can golf this any more...
```
import re
n=input()
f=input()
o=''
p=0
for i in re.finditer('\d+',f):o+=f[p:i.start()]+str(int(i.group())*int(n));p=i.end()
o+=f[p:]
print(o)
```
Example:
```
3     # This is input
h3110 # This is input
h9330 # This is output
10
hello100 hello100
hello1000 hello1000
```
[Answer]
# Mathematica ~~71~~ 61
With 10 chars saved thanks to Martin Buttner.
Spaces in code are for readability.
`f` is a function in which `s` is the input string and `n` is the number to multiply discovered string numbers by.
```
 StringReplace[#, a : DigitCharacter .. :> ToString[#2 FromDigits@a]] &
```
---
## Examples
```
 s="This 1 is22a 3352sentence 50"
```
Integer
```
StringReplace[#, a : DigitCharacter .. :> ToString[#2 FromDigits@a]] &@@{s, 3}
```
> 
> "This 3 is66a 10056sentence 150"
> 
> 
> 
---
[Answer]
## Ruby 40
```
a,b=$*
p a.gsub(/\d+/){|s|s.to_i*b.to_i}
```
Input from stdin.
Example run:
```
$ ruby mult.rb "This 1 is22a 3352sentence 50" 3 
"This 3 is66a 10056sentence 150"
```
Online demo: <http://ideone.com/4BiHC8>
[Answer]
# Lua: ~~73~~ 69 characters
```
r=io.read
s=r()n=r()s=s:gsub("%d+",function(m)return m*n end)print(s)
```
Sample run:
```
bash-4.3$ lua -e 'r=io.read;s=r()n=r()s=s:gsub("%d+",function(m)return m*n end)print(s)' <<< $'This 1 is22a 3352sentence 50\n3'
This 3 is66a 10056sentence 150
```
[Answer]
## JavaScript, ES6, 43 characters
This is my first attempt at golfing!
```
(p=prompt)(p(n=p()).replace(/\d+/g,y=>y*n))
```
Run this in latest Firefox's Console. The first input is the number and the second input is the string from which the numbers are to be multiplied with the first input number.
The final prompt lists the output.
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal) `s`, 8 bytes
```
⁽±Ḋƛ⌊⁰*∨
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyJzIiwiIiwi4oG9wrHhuIrGm+KMiuKBsCriiKgiLCIiLCIxMzR0aGlzIDEyM3Rlc3Qgc3RyaW5nNTQgMTAwXG4zIl0=)
[Answer]
# Perl - 48 chars
```
$n=<>;print/\d/?$_*$n:$_ for(<>=~/(\d+)|(\D+)/g)
```
Read a number on the first line, then read a sentence and break it into chunks of either digits or non digits. Print the non digits as they are, and the numbers get multiplied.
[Answer]
# J - 63 char
Program reads in the number, and then the sentence.
```
;(*&.".&(1!:1]1)^:(0{i)(<@);.1~1,2~:/\i=.e.&'0123456789')1!:1]1
```
Explained by explosion:
```
;(*&.".&(1!:1]1)^:(0{i)(<@);.1~1,2~:/\i=.e.&'0123456789')1!:1]1
                                                         1!:1]1  NB. read sentence
                                         e.&'0123456789'         NB. is digit? bool vector
                                      i=.                        NB. save to i
                                 2  /\                           NB. between adjacent chars:
                                  ~:                             NB.  true if not equal
                               1,                                NB. pad to sentence length
 (                         ;.1~                         )        NB. cut the sentence
                ^:(0{i)                                          NB. if cut is digits:
  *&.".                                                          NB.  multiply as number
       &(1!:1]1)                                                 NB.  with user input
;                                                                NB. rejoin sentence
```
If we get to use J's PCRE library and make the sentence come first, we can knock this down to **54 characters**:
```
;_2(,*&.".&(1!:1]1)&.>)/\'\d+'(rxmatches rxcut])1!:1]1
```
Explained by explosion:
```
                                                1!:1]1  NB. read in sentence
                         '\d+'(rxmatches       )        NB. all /\d+/ matches
                              (          rxcut])        NB. cut by those matches
 _2                     \                               NB. on each nonmatch-match pair:
   (               &.>)/                                NB.  take the match
     *&.".                                              NB.  multiply as number
          &(1!:1]1)                                     NB.  by user input
   (,                 )                                 NB.  prepend nonmatch
;                                                       NB. rejoin sentence
```
J is bad at this, what can I say. It's a inconvenient because J's so nonimperative.
Some examples:
```
   ;(*&.".&(1!:1]1)^:(0{i)(<@);.1~1,2~:/\i=.e.&'0123456789')1!:1]1
3
This 1 is22a 3352sentence 50
This 3 is66a 10056sentence 150
   ;(*&.".&(1!:1]1)^:(0{i)(<@);.1~1,2~:/\i=.e.&'0123456789')1!:1]1
100
N0 R3GUL4R 3XPR35510N5 1N J M4K35 M3 54D ALS0
N0 R300GUL400R 300XPR3551000N500 100N J M400K3500 M300 5400D ALS0
   0!:0 <'system\main\regex.ijs'  NB. this is usually preloaded by J on startup anyway
   ;_2(,*&.".&(1!:1]1)&.>)/\'\d+'(rxmatches rxcut])1!:1]1
TH4T'5 M4RG1N411Y B3TT3R
0
TH0T'0 M0RG0N0Y B0TT0R
```
[Answer]
# CJam - 35
```
li:X;lN+{_sA,s-,{])\_!!{iX*}*oo}*}/
```
Try it at <http://cjam.aditsu.net/>
Sample input:
```
7
CJ4M W1LL H4V3 R3GUL4R 3XPR35510N5 L4T3R
```
Sample output:
```
CJ28M W7LL H28V21 R21GUL28R 21XPR248570N35 L28T21R
```
**Explanation:**
The program goes through each character, collecting the digits on the stack, and for each non-digit it first prints the collected number (if any) multiplied by the numeric input, then prints the character.
`li:X;` reads the numeric input and stores it in X  
`lN+` reads the string and appends a newline (it helps with trailing numbers)  
`{…}/` for each character in the string  
- `_s` copies the character and converts to string  
- `A,s-,` removes all the digits and counts the remaining characters; the result will be 0 if the character was a digit or 1 if not  
- `{…}*` executes the block if the count was 1 (i.e. non-digit); for digits it does nothing, so they remain on the stack  
-- `]` collects the characters from the stack into an array (i.e. a string); the characters are any digits from the previous iterations, plus the current character  
-- `)\` separates the last item (the current character) and moves it before the (remaining) string  
-- `_!!` copies the string and converts it to a boolean value - 0 if empty, 1 if not  
-- `{…}*` executes the block if the string was not empty, i.e. we had some digits before the current non-digit character  
--- `iX*` converts the string to integer and multiplies by X  
-- `o` prints the top of the stack - either the multiplied number or the empty string if we didn't have a number  
-- `o` (the 2nd one) prints the new top of the stack - the current non-digit character
[Answer]
# Haskell (161)
## Golfed
```
main=do{n<-getLine;l<-getContents;let{g c(t,s)|c>'/'&&c<':'=(c:t,s)|t/=""=([],c:(show.(*(read n)).read$t)++s)|True=(t,c:s)};putStr.tail.snd.foldr g("","")$' ':l}
```
## Ungolfed
```
modify :: (Show a, Read a) => (a -> a) -> String -> String
modify f = show . f . read
main=do
  number <- fmap read $ getLine    -- get number  
  l <- getContents                 -- get input
  -- if the current character is a digit, add it to the digits
  -- if the current character isn't a digit, and we have collected
  --    some digits, modify them and add them to the string
  -- otherwise add the current characters to the string
  let go current (digits , string) 
        | current `elem` ['0'..'9'] = (current : digits, string)
        | not (null digits)         = ([], current:(modify (*number) digits) ++ string)
        | otherwise                 = (digits, current:string)
  -- since the result of `go` is a pair, take the second value,
  -- remove the head (it's a space, in order to convert digits at the start)
  -- and print it
  putStr . tail . snd . foldr go ("","")$' ':l
```
Unfortunately, Haskell doesn't have a Regex library in its [Prelude](http://hackage.haskell.org/package/base-4.7.0.1/docs/Prelude.html).
[Answer]
# flex(-lexer) (94 89 characters)
```
 int m;main(c,v)char**v;{m=atoi(*++v);yylex();}
%%
[0-9]+ {printf("%d",m*atoi(yytext));}
```
Ungolfed version which doesn't segfault if you forget the command-line argument (not much longer):
```
%{
#define YY_DECL int y(int m)
%}
%option noyywrap noinput nounput
%%
[0-9]+ {printf("%d",m*atoi(yytext));}
%%
int main(int argc, char** argv) {
  return (argc > 1) ? y(atoi(argv[1])) : 1;
}
```
Compile with:
```
flex -o m.c m.l
cc -o m m.c -lfl
```
or:
```
flex --noyywrap -o m.c m.l
cc -o m m.c
```
Eg:
```
$ ./m 163
This 1 is22a 3352sentence 50
This 163 is3586a 546376sentence 8150
```
[Answer]
# [`Groovy` - 124](http://ideone.com/eOJGmC)
```
Scanner s=new Scanner(System.in)
def x=s.nextLine()
def n=s.nextInt()
x=x.replaceAll(/\d+/,{it->it.toInteger()*n})
println x
```
*Click on the title to see the runnable example* 
# Examples Tried:
> 
> This 1 is22a 3352sentence 50  
> 
>  3  
> 
>  This 3 is66a 10056sentence 150 
> 
> 
> 
---
> 
> This 1 is22a 3352sentence 50  
> 
>  42  
> 
>  This 42 is924a 140784sentence 2100
> 
> 
> 
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 9 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
```
r"%d+"_*V
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=ciIlZCsiXypW&input=IlRoaXMgMSBpczIyYSAzMzUyc2VudGVuY2UgNTAiCjM)
[Answer]
# GNU Awk: 86 characters
```
s{n=split(s RS,a,/[^0-9]+/,d);while(++i<n)printf"%s%s",a[i]==""?"":a[i]*$1,d[i]}{s=$0}
```
Sample run:
```
bash-4.3$ awk 's{n=split(s RS,a,/[^0-9]+/,d);while(++i<n)printf"%s%s",a[i]==""?"":a[i]*$1,d[i]}{s=$0}' <<< $'This 1 is22a 3352sentence 50\n3'
This 3 is66a 10056sentence 150
```
[Answer]
# PHP - 75/115 68/109
Two versions, newer php versions can do this:
```
echo preg_replace_callback("/\d+/",function($m){return$m[0]*$f;},$s);
```
Older php versions: I did not count the newline, added those for readability. 
```
function a($s){echo preg_replace_callback("/\d+/",b,$s);}
function b($i){global$f;return$i[0]*$f;}
a($s,$f);
```
Example input+output
```
$s = "ab11cd22"; // string
$f =  3; // -> output: ab36cd69
$f = -2; // -> output: ab-24cd-46
```
Kinda difficult, the words 'function' and 'preg\_replace\_callback' take up a lot of chars.  
The space after `global` and `return` arent needed if followed by a $var (-2 chars)
[Answer]
## C (~~142~~ 134 characters)
```
main(a,b)char**b;{char*c=b++[2],*d="0123456789";for(;*c;c+=strspn(c
,d))write(1,c,a=strcspn(c,d)),dprintf(1,"%d",atoi(*b)*atoi(c+=a));}
```
Newline inserted for enhanced legibility. Pass the factor as the first, the string as the second command line option. This implementation requires the `dprintf` function which is part of POSIX.1 2008 and might not be available on Windows. Here is the unminified source:
```
/*
 * Multiply all numbers in a string by a number.
 * http://codegolf.stackexchange.com/q/37110/134
 * Solution by user FUZxxl
 */
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
extern int
main(int count, char **argv)
{
    char *str = argv++[2], *digits = "0123456789";
    while (*str) {          /* as long as we have not reached the end */
        count = strcspn(str, digits);
        write(1, str, count);
        dprintf(1, "%d", atoi(*argv) * atoi(str += count));
        str += strspn(str, digits);
    }
}
```
## Improvements
* 142 → 134: Use `strspn` and `strcspn` instead of looping over the string.
[Answer]
# Python 89
```
import re,sys
j,n,s=sys.argv
print re.sub('(\d+)',lambda m:str(int(m.group())*int(n)),s)
```
eg:
```
# python numberstring.py 3 '1shoop da2 w007p!'
3shoop da6 w21p!
```
[Answer]
# Rebol - 117
```
n: do input d: charset"0123456789"parse s: input[any[b: some d e:(e: insert b n * do take/part b e):e | skip]]print s
```
  
Ungolfed:
```
n: do input 
d: charset "0123456789"
parse s: input [
    any [
        b: some d e: (e: insert b n * do take/part b e) :e
        | skip
    ]
]
print s
```
[Answer]
## Clojure - 141 140 128 chars
I'm a Clojure newbie, but FWIW:
```
(let[[a b]*command-line-args*](println ((fn[s n](clojure.string/replace s #"\d+"#(str(*(read-string %)(read-string n)))))a b)))
```
Sample run:
```
bash$ java -jar clojure-1.6.0.jar multstr.clj "This 1 is22a 3352sentence 50" 3  
This 3 is66a 10056sentence 150
```
Ungolfed (ugly but hopefully somewhat easier to read):
```
(let [[a b] *command-line-args*]
    (println ( (fn [s n] 
                    (clojure.string/replace 
                        s 
                        #"\d+" 
                        #(str (* (read-string %) (read-string n)))))
                    a b)))
```
[Answer]
## Python - 142
```
import re
s=raw_input()
i=int(raw_input())
print ''.join([x[0]+str(int(x[1])*i) for x in filter(None,re.findall('(\D*)(\d*)',s)) if x[0]!=''])
```
[Answer]
## Java 218
Someone had to do java. The input string are 2 token on the command line.
java M 'This 1 is22a 3352sentence 50' 3
```
public class M{
    public static void main(String[]a) {
        int m=new Integer(a[1]),n=0,b=0;
        String s="";
        for(char c:a[0].toCharArray()){
            if(c<48|c>57)s=b>(b=0)?s+m*n+c:s+c;
            else n=b*n+c-38-(b=10);
        }
        System.out.println(b>0?s+m*n:s);
    }
}
```
[Answer]
# Two answer: [perl](/questions/tagged/perl "show questions tagged 'perl'") + [bash](/questions/tagged/bash "show questions tagged 'bash'")
## Pure bash (~262)
First, there is an *not so short* **pure** bash version (no fork, no external binaries)!
```
mn () { 
    if [[ $1 =~ ^(.*[^0-9]|)([0-9]+)([^0-9].*|)$ ]]; then
        local num=${BASH_REMATCH[2]} rhs="${BASH_REMATCH[3]}";
        mn "${BASH_REMATCH[1]}" ${2:-3} l;
        echo -n "$[num*${2:-3}]$rhs";
    else
        echo -n "$1";
    fi;
    [ "$3" ] || echo
}
```
Let's show:
```
mn "This 1 is22a 3352sentence 50" 42
This 42 is924a 140784sentence 2100
```
(Which is a totally improbable sentence)
## Perl little obfuscated (for fun only)
This version (based on [@Chilemagic's](https://codegolf.stackexchange.com/a/37113/10961) answer) is not shorter, but designed as a ***totem*** script:
> 
> `cat <<eof >mn.pl`
> 
> 
> 
```
#!/usr/bin/perl          -sp
                      eval eval'"'
                      .('['^'(')
           .'/\\'.'\\'.('`'|'$').'+'.'/\\$\&'
                        .'*\\$'
                      .('`'|'.').'/'
                      .('`'|"'")
                      .('`'|'%').'"'
```
> 
> `eof
>  chmod +x mn.pl`
> 
> 
> 
Sample run:
```
./mn.pl -n=2 <<<$'This 1 is22a 3352sentence 50\n21.'
This 2 is44a 6704sentence 100
42.
```
]