tags:

views:

128

answers:

2

Here is another Regex questions for the experts

I am building an Mysql insert with regex...

This is what the insert looks like... so far

(#text1#,#text2#,#text3#,#text4#,#text5#,#text6#, #text7#, #text8#, #text9#), (#text1#,#text2#,#text3#,#text4#,#text5#,#text6#, #text7#, #text8#, #text9#), (#text1#,#text2#,#text3#,#text4#,#text5#,#text6#, #text7#, #text8#, #text9#);

In a previous question someone helped me to write this regex expression to delete a value that is smalled than the example above

var stripped30 = htstring30.replace(/\((?:[^#\n]*?#[^#\n]*?#[,\s]?){0,8}\)[,;]\s*/ig, '');

This will remove the exeption below and delete it, leaving me with only the 9 tables that I want...

(#text1#,#text2#,#text3#,#text4#,#text5#,#text6#),

Now I basically want to do the same thing but this time delete all the exceptions bigger than 9 - Can anybody please assist me to do this..

(#text1#,#text2#,#text3#,#text4#,#text5#,#text6#, #text7#, #text8#, #text9#),
(#text1#,#text2#,#text3#,#text4#,#text5#,#text6#, #text7#, #text8#, #text9#,  #text10#),
(#text1#,#text2#,#text3#,#text4#,#text5#,#text6#, #text7#, #text8#, #text9#,  #text10#,  #text11#);
(#text1#,#text2#,#text3#,#text4#,#text5#,#text6#, #text7#, #text8#, #text9#),
(#text1#,#text2#,#text3#,#text4#,#text5#,#text6#, #text7#, #text8#, #text9#),
(#text1#,#text2#,#text3#,#text4#,#text5#,#text6#, #text7#, #text8#, #text9#);

So that when their is an exception bigger than 9 that I may delete it

Thanks

A: 

You could use this regular expression to remove every line that has not 9 entries:

/^(?!\s*\((?:#[^#\n]*#(?:\s*,\s*#[^#\n]*#){8})\)[,;]\s*$).*/mg
Gumbo
I have tried it but it deleted everything /^(?!\s*\((?:#[^#\n]*#(?:\s*,\s*#[^#\n]*#){8}\)[,;]\s*$).*[^;];?$/mg I have received an error when initially using it, /^(?!\s*\((?:#[^#\n]*#(?:\s*,\s*#[^#\n]*#){8}\)[,;]\s*$)).*[^;];?$/mg and added a closing bracket
Gerald Ferreira
@Gerald Ferreira: Fixed it.
Gumbo
A: 

you could try the following:

var stripped30 = htstring30.replace(/\((?:[^#\n]*?#[^#\n]*?#[,\s]?){10,}\)[,;]\s*/ig, '');

where the blank after the 10, indicates that there is no upper bound.

edit:

using my answer from the previous question, but updating it as I have to your example above, produces, for me, good results:

\(([\s]*#[^#]+#[\s]*,?){10,}\)[,;]*

let me know how you fare.

akf
Hi AKF I have tried your solution and it is not working either, althoug it actually shows me all the ones that is not matching the problem... but deleting the ones that I want to keep... so if it could be reversed as it is, it may actually work
Gerald Ferreira