Share On Twitter Facebook Google+ LinkedIn Pinterest Tumblr Reddit
Question

I can not split random numbers in parentheses. I try regex but doesnt work.

Tags: split regex javascript node.js
Date:
Status:Resolved
Question Id:15
I want to convert int(11) to int . How can I remove "(11)". I can not delete "(11)" directly.
Because number 11 can be change. I want to be dynamic code for random numbers.

CREATE TABLE users ( ID int(11), name VARCHAR(30), email VARCHAR(30) );
The solution must be;
CREATE TABLE users (
  ID int,
  name VARCHAR(30),
  email VARCHAR(30)
);

I try to this;
        createTableStatement=createTableStatement.split(/int(\d\d/)).join("int")
 

it does not work. Coulkd you help me?

Answer
Date:
Correct:No

In Python-style regex, \d matches any individual digit. If you're seeing something that doesn't seem to do that, please provide the full regex you're using, as opposed to just describing that one particular symbol.

>>> import re
>>> re.match(r'\d', '3')
<_sre.SRE_Match object at 0x02155B80>
>>> re.match(r'\d', '2')
<_sre.SRE_Match object at 0x02155BB8>
>>> re.match(r'\d', '1')
<_sre.SRE_Match object at 0x02155B80>

Decimal digit character: \d \d matches any decimal digit. It is equivalent to the \p{Nd} regular expression pattern, which includes the standard decimal digits 0-9 as well as the decimal digits of a number of other character sets.

 

If ECMAScript-compliant behavior is specified, \d is equivalent to [0-9]. For information on ECMAScript regular expressions, see the "ECMAScript Matching Behavior" section in Regular Expression Options.



 
Answer
Date:
Correct:No

can you try this

split(/int([^0-9])/)
/[0-9]+/  - one or more digits; greediness defined by the PCRE_UNGREEDY option
/[0-9]+?/ - one or more digits, but as few as possible (non-greedy)
/[0-9]++/ - one or more digits, but as many as possible (greedy, default)
Answer
Date:
Correct:No

no it doesnt work. it gives me a syntax error. I want sirnode to find a solution?

Answer
Date:
Correct:Yes

Sir Node always find a solution.

        createTableStatement=createTableStatement.split(/int[\(\d\d\)]+/).join("int")
 

this code is tested and works. 

Answer
Date:
Correct:No

thank you sirnode !! this works.

Your Answer

Review Your Answer