RegEx: Finding semicolon between double quotes
I am just starting with regular expressions. I need to find all the cases in the text, where there is semicolon in the string between double quotes. So I am searching for the cases like
"something;something"
"something ; something"
"something; something"
"something ;something"
I found code to find strings between double quotes:
(["'])(?:(?=(\?))2.)*?1
Can you help me modify it so I will find cases like I mentioned above?
regex
add a comment |
I am just starting with regular expressions. I need to find all the cases in the text, where there is semicolon in the string between double quotes. So I am searching for the cases like
"something;something"
"something ; something"
"something; something"
"something ;something"
I found code to find strings between double quotes:
(["'])(?:(?=(\?))2.)*?1
Can you help me modify it so I will find cases like I mentioned above?
regex
add a comment |
I am just starting with regular expressions. I need to find all the cases in the text, where there is semicolon in the string between double quotes. So I am searching for the cases like
"something;something"
"something ; something"
"something; something"
"something ;something"
I found code to find strings between double quotes:
(["'])(?:(?=(\?))2.)*?1
Can you help me modify it so I will find cases like I mentioned above?
regex
I am just starting with regular expressions. I need to find all the cases in the text, where there is semicolon in the string between double quotes. So I am searching for the cases like
"something;something"
"something ; something"
"something; something"
"something ;something"
I found code to find strings between double quotes:
(["'])(?:(?=(\?))2.)*?1
Can you help me modify it so I will find cases like I mentioned above?
regex
regex
asked Nov 12 '18 at 14:43
JanFi86
24111
24111
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
You could use a negated character class where you can add what you don't want to match. If there can be only 1 semicolon in the string, then you can also add that to the character class, else you could use [^"rn]*
where there can be multiple occurrences of ;
"([^"rn;]*;[^";rn]*)"
That would match
"
Match literally
(
Capturing group
[^"rn;]*
Match 0+ times not a"
, newline or semicolon
;
Match literally
[^"rn;]*
Match 0+ times not a"
, newline or semicolon
)
Close capturing group
"
Match literally
Your value is in the first capturing group.
Regex demo
If you don't want to match just a semicolon between double quotes you could prepend a negative lookahead:
(?!";")"([^"rn;]*;[^";rn]*)"
Thank you for your solution. Can you modify it so it ommits cases like ";" ? That means it ommits cases where there is just semicolon between double quotes, without any characters or spaces. Thank you in advance.
– JanFi86
Nov 12 '18 at 15:01
1
@JanFi86 Do you mean like this? regex101.com/r/EMqrjV/3
– The fourth bird
Nov 12 '18 at 15:03
1
Exactly! Thank you so much!
– JanFi86
Nov 12 '18 at 15:06
add a comment |
<?php
$input = <<<INPUT
a
"something;something"
b
"something ; something"
c
"something; something"
d
"something ;something"
e
INPUT;
preg_match_all("/"([^"]+;[^"]+)"/im", $input, $m);
print_r($m);
/*
Array
(
[0] => Array
(
[0] => "something;something"
[1] => "something ; something"
[2] => "something; something"
[3] => "something ;something"
)
[1] => Array
(
[0] => something;something
[1] => something ; something
[2] => something; something
[3] => something ;something
)
)
*/
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53264547%2fregex-finding-semicolon-between-double-quotes%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You could use a negated character class where you can add what you don't want to match. If there can be only 1 semicolon in the string, then you can also add that to the character class, else you could use [^"rn]*
where there can be multiple occurrences of ;
"([^"rn;]*;[^";rn]*)"
That would match
"
Match literally
(
Capturing group
[^"rn;]*
Match 0+ times not a"
, newline or semicolon
;
Match literally
[^"rn;]*
Match 0+ times not a"
, newline or semicolon
)
Close capturing group
"
Match literally
Your value is in the first capturing group.
Regex demo
If you don't want to match just a semicolon between double quotes you could prepend a negative lookahead:
(?!";")"([^"rn;]*;[^";rn]*)"
Thank you for your solution. Can you modify it so it ommits cases like ";" ? That means it ommits cases where there is just semicolon between double quotes, without any characters or spaces. Thank you in advance.
– JanFi86
Nov 12 '18 at 15:01
1
@JanFi86 Do you mean like this? regex101.com/r/EMqrjV/3
– The fourth bird
Nov 12 '18 at 15:03
1
Exactly! Thank you so much!
– JanFi86
Nov 12 '18 at 15:06
add a comment |
You could use a negated character class where you can add what you don't want to match. If there can be only 1 semicolon in the string, then you can also add that to the character class, else you could use [^"rn]*
where there can be multiple occurrences of ;
"([^"rn;]*;[^";rn]*)"
That would match
"
Match literally
(
Capturing group
[^"rn;]*
Match 0+ times not a"
, newline or semicolon
;
Match literally
[^"rn;]*
Match 0+ times not a"
, newline or semicolon
)
Close capturing group
"
Match literally
Your value is in the first capturing group.
Regex demo
If you don't want to match just a semicolon between double quotes you could prepend a negative lookahead:
(?!";")"([^"rn;]*;[^";rn]*)"
Thank you for your solution. Can you modify it so it ommits cases like ";" ? That means it ommits cases where there is just semicolon between double quotes, without any characters or spaces. Thank you in advance.
– JanFi86
Nov 12 '18 at 15:01
1
@JanFi86 Do you mean like this? regex101.com/r/EMqrjV/3
– The fourth bird
Nov 12 '18 at 15:03
1
Exactly! Thank you so much!
– JanFi86
Nov 12 '18 at 15:06
add a comment |
You could use a negated character class where you can add what you don't want to match. If there can be only 1 semicolon in the string, then you can also add that to the character class, else you could use [^"rn]*
where there can be multiple occurrences of ;
"([^"rn;]*;[^";rn]*)"
That would match
"
Match literally
(
Capturing group
[^"rn;]*
Match 0+ times not a"
, newline or semicolon
;
Match literally
[^"rn;]*
Match 0+ times not a"
, newline or semicolon
)
Close capturing group
"
Match literally
Your value is in the first capturing group.
Regex demo
If you don't want to match just a semicolon between double quotes you could prepend a negative lookahead:
(?!";")"([^"rn;]*;[^";rn]*)"
You could use a negated character class where you can add what you don't want to match. If there can be only 1 semicolon in the string, then you can also add that to the character class, else you could use [^"rn]*
where there can be multiple occurrences of ;
"([^"rn;]*;[^";rn]*)"
That would match
"
Match literally
(
Capturing group
[^"rn;]*
Match 0+ times not a"
, newline or semicolon
;
Match literally
[^"rn;]*
Match 0+ times not a"
, newline or semicolon
)
Close capturing group
"
Match literally
Your value is in the first capturing group.
Regex demo
If you don't want to match just a semicolon between double quotes you could prepend a negative lookahead:
(?!";")"([^"rn;]*;[^";rn]*)"
edited Nov 12 '18 at 15:09
answered Nov 12 '18 at 14:48
The fourth bird
20.7k71326
20.7k71326
Thank you for your solution. Can you modify it so it ommits cases like ";" ? That means it ommits cases where there is just semicolon between double quotes, without any characters or spaces. Thank you in advance.
– JanFi86
Nov 12 '18 at 15:01
1
@JanFi86 Do you mean like this? regex101.com/r/EMqrjV/3
– The fourth bird
Nov 12 '18 at 15:03
1
Exactly! Thank you so much!
– JanFi86
Nov 12 '18 at 15:06
add a comment |
Thank you for your solution. Can you modify it so it ommits cases like ";" ? That means it ommits cases where there is just semicolon between double quotes, without any characters or spaces. Thank you in advance.
– JanFi86
Nov 12 '18 at 15:01
1
@JanFi86 Do you mean like this? regex101.com/r/EMqrjV/3
– The fourth bird
Nov 12 '18 at 15:03
1
Exactly! Thank you so much!
– JanFi86
Nov 12 '18 at 15:06
Thank you for your solution. Can you modify it so it ommits cases like ";" ? That means it ommits cases where there is just semicolon between double quotes, without any characters or spaces. Thank you in advance.
– JanFi86
Nov 12 '18 at 15:01
Thank you for your solution. Can you modify it so it ommits cases like ";" ? That means it ommits cases where there is just semicolon between double quotes, without any characters or spaces. Thank you in advance.
– JanFi86
Nov 12 '18 at 15:01
1
1
@JanFi86 Do you mean like this? regex101.com/r/EMqrjV/3
– The fourth bird
Nov 12 '18 at 15:03
@JanFi86 Do you mean like this? regex101.com/r/EMqrjV/3
– The fourth bird
Nov 12 '18 at 15:03
1
1
Exactly! Thank you so much!
– JanFi86
Nov 12 '18 at 15:06
Exactly! Thank you so much!
– JanFi86
Nov 12 '18 at 15:06
add a comment |
<?php
$input = <<<INPUT
a
"something;something"
b
"something ; something"
c
"something; something"
d
"something ;something"
e
INPUT;
preg_match_all("/"([^"]+;[^"]+)"/im", $input, $m);
print_r($m);
/*
Array
(
[0] => Array
(
[0] => "something;something"
[1] => "something ; something"
[2] => "something; something"
[3] => "something ;something"
)
[1] => Array
(
[0] => something;something
[1] => something ; something
[2] => something; something
[3] => something ;something
)
)
*/
add a comment |
<?php
$input = <<<INPUT
a
"something;something"
b
"something ; something"
c
"something; something"
d
"something ;something"
e
INPUT;
preg_match_all("/"([^"]+;[^"]+)"/im", $input, $m);
print_r($m);
/*
Array
(
[0] => Array
(
[0] => "something;something"
[1] => "something ; something"
[2] => "something; something"
[3] => "something ;something"
)
[1] => Array
(
[0] => something;something
[1] => something ; something
[2] => something; something
[3] => something ;something
)
)
*/
add a comment |
<?php
$input = <<<INPUT
a
"something;something"
b
"something ; something"
c
"something; something"
d
"something ;something"
e
INPUT;
preg_match_all("/"([^"]+;[^"]+)"/im", $input, $m);
print_r($m);
/*
Array
(
[0] => Array
(
[0] => "something;something"
[1] => "something ; something"
[2] => "something; something"
[3] => "something ;something"
)
[1] => Array
(
[0] => something;something
[1] => something ; something
[2] => something; something
[3] => something ;something
)
)
*/
<?php
$input = <<<INPUT
a
"something;something"
b
"something ; something"
c
"something; something"
d
"something ;something"
e
INPUT;
preg_match_all("/"([^"]+;[^"]+)"/im", $input, $m);
print_r($m);
/*
Array
(
[0] => Array
(
[0] => "something;something"
[1] => "something ; something"
[2] => "something; something"
[3] => "something ;something"
)
[1] => Array
(
[0] => something;something
[1] => something ; something
[2] => something; something
[3] => something ;something
)
)
*/
answered Nov 12 '18 at 14:48
ZiTAL
1,88232340
1,88232340
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53264547%2fregex-finding-semicolon-between-double-quotes%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown