开发者

Regex pattern to match where my code breaks

I have the following values that I want to place into a mysql db

The pattern should look as follows, I need a regex to make sure that the pattern is always开发者_高级运维 as follows:

('', '', '', '', '')

In some rare execution of my code, I hower get the following output where one of the apostrophes disapear. it dissapears every now and then on the 4th record. like in the code below where I placed the *

('1', '2576', '1', '*, 'y')

anyideas to solve this will be welcomed!

This should be able to match one of the times the code breaks

string.replace(/, \',/ig, ', \'\',');

how would I do it if it is like this

('1', '2576', '1', 'where I have text here and it breaks at the end*, 'y')

I am using javascript and asp

I think the solution would be something like this

string.replace(/, \'[a-zA-Z0-9],/ig, ', \'\','); but not exactly sure how to write it

This is almost the solution that I am looking for...

string.replace(/[a-zA-Z0-9], \'/ig, '\', \'');

this code however replaces the last letter of the text with the ', ' so if the text inside the string is 'approved, ' it will replace the 'approve', ' and cut off the letter d

I know there is a way that you can reference it not to remove the last letter but not sure how to do it


Is this what you're looking for? It matches when all but the last field is missing the '

\('.*?'\)


Your regular expression, would be something like this:

^\('.*?',\ '.*?',\ '.*?',\ '.*?',\ '.*?'\)$

you could check if your string matchs in ASP.net with some code similar to this:

   Match m = Regex.Match(inputString, @"^\('.*?',\ '.*?',\ '.*?',\ '.*?',\ '.*?'\)$");
   if (!m.Success)
   {
         //some fix logic here
   }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜