c# Regex for all except single,double quotes and comma [duplicate]
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.
c# regex
marked as duplicate by Wiktor Stribiżew
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.
add a comment |
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.
c# regex
marked as duplicate by Wiktor Stribiżew
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
add a comment |
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.
c# regex
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
c# regex
asked Jan 2 at 19:02
karenkaren
927
927
marked as duplicate by Wiktor Stribiżew
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
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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);
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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);
add a comment |
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);
add a comment |
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);
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);
answered Jan 2 at 19:24


JammoDJammoD
321413
321413
add a comment |
add a comment |
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