Treat list of CNPJ's with regular expression

-1

I have a list of CNPJ's, I would like to take this list and add single quotes and separate each with a comma, doing it with regular expression.

Eg: My list:

  

32132132132 32132132132 321321321323 32132132132132

How do I wish to stay:

  

'32132132132', '32132132132', '321321321323', '32132132132132'

    
asked by anonymous 26.03.2018 / 19:54

1 answer

0

I honestly see no reason to use Regular Expressions in anything simple.

In PHP use explode and join

$str = '32132132132 32132132132 321321321323 32132132132132';
$exp = explode(' ', $str);
echo "'" . join("';'", $exp) . "'";
  

See working at repl.it

In Python use split and < a href="https://docs.python.org/2/library/string.html#string.join"> join

str = '32132132132 32132132132 321321321323 32132132132132';
exp = str.split();
print("'" + "';'".join(exp) + "'")
  

See working at repl.it

In Java use split " and join

String link = "32132132132 32132132132 321321321323 32132132132132";
String[] partes = link.split(" ");
System.out.println("'" + String.join("';'", partes) + "'");
  

See working at repl.it

In JavaScript use and split

let str = '32132132132 32132132132 321321321323 32132132132132';
let res = "'" + str.split(' ').join("';'") + "'";
console.log(res)
    
27.03.2018 / 17:05