c# Regex for all except single,double quotes and comma [duplicate]












-1
















This question already has an answer here:




  • Regular Expression Except this Characters

    4 answers



  • How to add double quotes to a string that is inside a variable?

    18 answers




I am trying to get a regex working but cannot get it right. I am trying to write a regex c# that would allow all special chars except comma, single quotes & double quotes. But cant get it to work.



I have the below code:



 Regex alphaNumericRegex = new Regex(@"^[w]*$", RegexOptions.IgnoreCase);


I tried using



^[^'",][a-zA-Z0-9~`!@#$%^&*()_+-={}|:;<>.?/]*$


where I thought the first negate set is for the chars which I dont want to allow.



But this does not work. There must be a simpler way to do this.



Sorry I know there are many regex posts around but somehow I cant get mine to work even after reading them.



Would appreciate inputs.










share|improve this question













marked as duplicate by Wiktor Stribiżew c#
Users with the  c# badge can single-handedly close c# questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 2 at 19:25


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • 4





    Do you mean to write @"^[^""',]*$" matching a string consisting of any 0+ chars other than double and single quotes and commas?

    – Wiktor Stribiżew
    Jan 2 at 19:04













  • @WiktorStribiżew You should post this as the answer.

    – Lews Therin
    Jan 2 at 19:07











  • Karen, what is the trouble here? Do you want to say you just failed to use a double quote in the string literal? I guess that was the main trouble with getting at the right expression.

    – Wiktor Stribiżew
    Jan 2 at 19:22













  • Yes thanks for this wiktor. This works fine. I had missing double quotes. Also I thought we had to use all the chars list which we also want to allow, which is not the case though.

    – karen
    Jan 2 at 19:40
















-1
















This question already has an answer here:




  • Regular Expression Except this Characters

    4 answers



  • How to add double quotes to a string that is inside a variable?

    18 answers




I am trying to get a regex working but cannot get it right. I am trying to write a regex c# that would allow all special chars except comma, single quotes & double quotes. But cant get it to work.



I have the below code:



 Regex alphaNumericRegex = new Regex(@"^[w]*$", RegexOptions.IgnoreCase);


I tried using



^[^'",][a-zA-Z0-9~`!@#$%^&*()_+-={}|:;<>.?/]*$


where I thought the first negate set is for the chars which I dont want to allow.



But this does not work. There must be a simpler way to do this.



Sorry I know there are many regex posts around but somehow I cant get mine to work even after reading them.



Would appreciate inputs.










share|improve this question













marked as duplicate by Wiktor Stribiżew c#
Users with the  c# badge can single-handedly close c# questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 2 at 19:25


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • 4





    Do you mean to write @"^[^""',]*$" matching a string consisting of any 0+ chars other than double and single quotes and commas?

    – Wiktor Stribiżew
    Jan 2 at 19:04













  • @WiktorStribiżew You should post this as the answer.

    – Lews Therin
    Jan 2 at 19:07











  • Karen, what is the trouble here? Do you want to say you just failed to use a double quote in the string literal? I guess that was the main trouble with getting at the right expression.

    – Wiktor Stribiżew
    Jan 2 at 19:22













  • Yes thanks for this wiktor. This works fine. I had missing double quotes. Also I thought we had to use all the chars list which we also want to allow, which is not the case though.

    – karen
    Jan 2 at 19:40














-1












-1








-1









This question already has an answer here:




  • Regular Expression Except this Characters

    4 answers



  • How to add double quotes to a string that is inside a variable?

    18 answers




I am trying to get a regex working but cannot get it right. I am trying to write a regex c# that would allow all special chars except comma, single quotes & double quotes. But cant get it to work.



I have the below code:



 Regex alphaNumericRegex = new Regex(@"^[w]*$", RegexOptions.IgnoreCase);


I tried using



^[^'",][a-zA-Z0-9~`!@#$%^&*()_+-={}|:;<>.?/]*$


where I thought the first negate set is for the chars which I dont want to allow.



But this does not work. There must be a simpler way to do this.



Sorry I know there are many regex posts around but somehow I cant get mine to work even after reading them.



Would appreciate inputs.










share|improve this question















This question already has an answer here:




  • Regular Expression Except this Characters

    4 answers



  • How to add double quotes to a string that is inside a variable?

    18 answers




I am trying to get a regex working but cannot get it right. I am trying to write a regex c# that would allow all special chars except comma, single quotes & double quotes. But cant get it to work.



I have the below code:



 Regex alphaNumericRegex = new Regex(@"^[w]*$", RegexOptions.IgnoreCase);


I tried using



^[^'",][a-zA-Z0-9~`!@#$%^&*()_+-={}|:;<>.?/]*$


where I thought the first negate set is for the chars which I dont want to allow.



But this does not work. There must be a simpler way to do this.



Sorry I know there are many regex posts around but somehow I cant get mine to work even after reading them.



Would appreciate inputs.





This question already has an answer here:




  • Regular Expression Except this Characters

    4 answers



  • How to add double quotes to a string that is inside a variable?

    18 answers








c# regex






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 2 at 19:02









karenkaren

927




927




marked as duplicate by Wiktor Stribiżew c#
Users with the  c# badge can single-handedly close c# questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 2 at 19:25


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by Wiktor Stribiżew c#
Users with the  c# badge can single-handedly close c# questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 2 at 19:25


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.










  • 4





    Do you mean to write @"^[^""',]*$" matching a string consisting of any 0+ chars other than double and single quotes and commas?

    – Wiktor Stribiżew
    Jan 2 at 19:04













  • @WiktorStribiżew You should post this as the answer.

    – Lews Therin
    Jan 2 at 19:07











  • Karen, what is the trouble here? Do you want to say you just failed to use a double quote in the string literal? I guess that was the main trouble with getting at the right expression.

    – Wiktor Stribiżew
    Jan 2 at 19:22













  • Yes thanks for this wiktor. This works fine. I had missing double quotes. Also I thought we had to use all the chars list which we also want to allow, which is not the case though.

    – karen
    Jan 2 at 19:40














  • 4





    Do you mean to write @"^[^""',]*$" matching a string consisting of any 0+ chars other than double and single quotes and commas?

    – Wiktor Stribiżew
    Jan 2 at 19:04













  • @WiktorStribiżew You should post this as the answer.

    – Lews Therin
    Jan 2 at 19:07











  • Karen, what is the trouble here? Do you want to say you just failed to use a double quote in the string literal? I guess that was the main trouble with getting at the right expression.

    – Wiktor Stribiżew
    Jan 2 at 19:22













  • Yes thanks for this wiktor. This works fine. I had missing double quotes. Also I thought we had to use all the chars list which we also want to allow, which is not the case though.

    – karen
    Jan 2 at 19:40








4




4





Do you mean to write @"^[^""',]*$" matching a string consisting of any 0+ chars other than double and single quotes and commas?

– Wiktor Stribiżew
Jan 2 at 19:04







Do you mean to write @"^[^""',]*$" matching a string consisting of any 0+ chars other than double and single quotes and commas?

– Wiktor Stribiżew
Jan 2 at 19:04















@WiktorStribiżew You should post this as the answer.

– Lews Therin
Jan 2 at 19:07





@WiktorStribiżew You should post this as the answer.

– Lews Therin
Jan 2 at 19:07













Karen, what is the trouble here? Do you want to say you just failed to use a double quote in the string literal? I guess that was the main trouble with getting at the right expression.

– Wiktor Stribiżew
Jan 2 at 19:22







Karen, what is the trouble here? Do you want to say you just failed to use a double quote in the string literal? I guess that was the main trouble with getting at the right expression.

– Wiktor Stribiżew
Jan 2 at 19:22















Yes thanks for this wiktor. This works fine. I had missing double quotes. Also I thought we had to use all the chars list which we also want to allow, which is not the case though.

– karen
Jan 2 at 19:40





Yes thanks for this wiktor. This works fine. I had missing double quotes. Also I thought we had to use all the chars list which we also want to allow, which is not the case though.

– karen
Jan 2 at 19:40












1 Answer
1






active

oldest

votes


















-1














By changing your regex to the following, you will allow all characters except commas, single quotes and double quotes.



Regex alphaNumericRegex = new Regex(@"^[^""',]*$", RegexOptions.IgnoreCase);





share|improve this answer






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    -1














    By changing your regex to the following, you will allow all characters except commas, single quotes and double quotes.



    Regex alphaNumericRegex = new Regex(@"^[^""',]*$", RegexOptions.IgnoreCase);





    share|improve this answer




























      -1














      By changing your regex to the following, you will allow all characters except commas, single quotes and double quotes.



      Regex alphaNumericRegex = new Regex(@"^[^""',]*$", RegexOptions.IgnoreCase);





      share|improve this answer


























        -1












        -1








        -1







        By changing your regex to the following, you will allow all characters except commas, single quotes and double quotes.



        Regex alphaNumericRegex = new Regex(@"^[^""',]*$", RegexOptions.IgnoreCase);





        share|improve this answer













        By changing your regex to the following, you will allow all characters except commas, single quotes and double quotes.



        Regex alphaNumericRegex = new Regex(@"^[^""',]*$", RegexOptions.IgnoreCase);






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 2 at 19:24









        JammoDJammoD

        321413




        321413

















            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

            How to fix TextFormField cause rebuild widget in Flutter