C#. Split string with separator by regex if separator is surrounded by something The Next CEO of Stack OverflowWhat is the difference between String and string in C#?Convert a string to an enum in C#Catch multiple exceptions at once?How do you convert a byte array to a hexadecimal string, and vice versa?How do you access the matched groups in a JavaScript regular expression?How do I get a consistent byte representation of strings in C# without manually specifying an encoding?Creating a comma separated list from IList<string> or IEnumerable<string>Get property value from string using reflection in C#C# Split A String By Another StringCheck whether a string matches a regex in JS
Text adventure game code
What can we do to stop prior company from asking us questions?
If I blow insulation everywhere in my attic except the door trap, will heat escape through it?
Anatomically Correct Mesopelagic Aves
How long to clear the 'suck zone' of a turbofan after start is initiated?
WOW air has ceased operation, can I get my tickets refunded?
How easy is it to start Magic from scratch?
Are there languages with no euphemisms?
When did Lisp start using symbols for arithmetic?
Why here is plural "We went to the movies last night."
Can a caster that cast Polymorph on themselves stop concentrating at any point even if their Int is low?
Return of the Riley Riddles in Reverse
How do we know the LHC results are robust?
Inappropriate reference requests from Journal reviewers
Unreliable Magic - Is it worth it?
How to Reset Passwords on Multiple Websites Easily?
How to write papers efficiently when English isn't my first language?
Science fiction (dystopian) short story set after WWIII
Can the Reverse Gravity spell affect the Meteor Swarm spell?
Why did we only see the N-1 starfighters in one film?
What does this shorthand mean?
Removing read access from a file
What do "high sea" and "carry" mean in this sentence?
What is the point of a new vote on May's deal when the indicative votes suggest she will not win?
C#. Split string with separator by regex if separator is surrounded by something
The Next CEO of Stack OverflowWhat is the difference between String and string in C#?Convert a string to an enum in C#Catch multiple exceptions at once?How do you convert a byte array to a hexadecimal string, and vice versa?How do you access the matched groups in a JavaScript regular expression?How do I get a consistent byte representation of strings in C# without manually specifying an encoding?Creating a comma separated list from IList<string> or IEnumerable<string>Get property value from string using reflection in C#C# Split A String By Another StringCheck whether a string matches a regex in JS
Given string "Hello.World"
I want to get an array [ "Hello.World" ]
Given string "Hello.World"
I want to get an array [ "Hello", "World" ]
c# regex
add a comment |
Given string "Hello.World"
I want to get an array [ "Hello.World" ]
Given string "Hello.World"
I want to get an array [ "Hello", "World" ]
c# regex
2
What do you want returned for"Hello\.World"
?
– Dour High Arch
Mar 21 at 16:29
1
(?<!\).
?
– Ahmed Abdelhameed
Mar 21 at 16:30
1
You want a "negative lookbehind"
– Blorgbeard
Mar 21 at 16:30
@DourHighArch the first case. I skipped @ to make it more readable. Sorry for non-obviousness
– Herrgott
Mar 21 at 16:35
add a comment |
Given string "Hello.World"
I want to get an array [ "Hello.World" ]
Given string "Hello.World"
I want to get an array [ "Hello", "World" ]
c# regex
Given string "Hello.World"
I want to get an array [ "Hello.World" ]
Given string "Hello.World"
I want to get an array [ "Hello", "World" ]
c# regex
c# regex
asked Mar 21 at 16:26
HerrgottHerrgott
210521
210521
2
What do you want returned for"Hello\.World"
?
– Dour High Arch
Mar 21 at 16:29
1
(?<!\).
?
– Ahmed Abdelhameed
Mar 21 at 16:30
1
You want a "negative lookbehind"
– Blorgbeard
Mar 21 at 16:30
@DourHighArch the first case. I skipped @ to make it more readable. Sorry for non-obviousness
– Herrgott
Mar 21 at 16:35
add a comment |
2
What do you want returned for"Hello\.World"
?
– Dour High Arch
Mar 21 at 16:29
1
(?<!\).
?
– Ahmed Abdelhameed
Mar 21 at 16:30
1
You want a "negative lookbehind"
– Blorgbeard
Mar 21 at 16:30
@DourHighArch the first case. I skipped @ to make it more readable. Sorry for non-obviousness
– Herrgott
Mar 21 at 16:35
2
2
What do you want returned for
"Hello\.World"
?– Dour High Arch
Mar 21 at 16:29
What do you want returned for
"Hello\.World"
?– Dour High Arch
Mar 21 at 16:29
1
1
(?<!\).
?– Ahmed Abdelhameed
Mar 21 at 16:30
(?<!\).
?– Ahmed Abdelhameed
Mar 21 at 16:30
1
1
You want a "negative lookbehind"
– Blorgbeard
Mar 21 at 16:30
You want a "negative lookbehind"
– Blorgbeard
Mar 21 at 16:30
@DourHighArch the first case. I skipped @ to make it more readable. Sorry for non-obviousness
– Herrgott
Mar 21 at 16:35
@DourHighArch the first case. I skipped @ to make it more readable. Sorry for non-obviousness
– Herrgott
Mar 21 at 16:35
add a comment |
1 Answer
1
active
oldest
votes
You can use a negative lookbehind using Regex.Split()
... something like:
Regex.Split(input, @"(?<!\).");
Sample fiddle
1
Life gets harder, of course, if you want to be able to escape the escapes...
– canton7
Mar 21 at 16:36
1
@canton7 I don't need to escape escapes. This answer fits my needs
– Herrgott
Mar 21 at 16:38
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%2f55285050%2fc-split-string-with-separator-by-regex-if-separator-is-surrounded-by-something%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use a negative lookbehind using Regex.Split()
... something like:
Regex.Split(input, @"(?<!\).");
Sample fiddle
1
Life gets harder, of course, if you want to be able to escape the escapes...
– canton7
Mar 21 at 16:36
1
@canton7 I don't need to escape escapes. This answer fits my needs
– Herrgott
Mar 21 at 16:38
add a comment |
You can use a negative lookbehind using Regex.Split()
... something like:
Regex.Split(input, @"(?<!\).");
Sample fiddle
1
Life gets harder, of course, if you want to be able to escape the escapes...
– canton7
Mar 21 at 16:36
1
@canton7 I don't need to escape escapes. This answer fits my needs
– Herrgott
Mar 21 at 16:38
add a comment |
You can use a negative lookbehind using Regex.Split()
... something like:
Regex.Split(input, @"(?<!\).");
Sample fiddle
You can use a negative lookbehind using Regex.Split()
... something like:
Regex.Split(input, @"(?<!\).");
Sample fiddle
edited Mar 21 at 16:36
answered Mar 21 at 16:35
JclJcl
20.6k24266
20.6k24266
1
Life gets harder, of course, if you want to be able to escape the escapes...
– canton7
Mar 21 at 16:36
1
@canton7 I don't need to escape escapes. This answer fits my needs
– Herrgott
Mar 21 at 16:38
add a comment |
1
Life gets harder, of course, if you want to be able to escape the escapes...
– canton7
Mar 21 at 16:36
1
@canton7 I don't need to escape escapes. This answer fits my needs
– Herrgott
Mar 21 at 16:38
1
1
Life gets harder, of course, if you want to be able to escape the escapes...
– canton7
Mar 21 at 16:36
Life gets harder, of course, if you want to be able to escape the escapes...
– canton7
Mar 21 at 16:36
1
1
@canton7 I don't need to escape escapes. This answer fits my needs
– Herrgott
Mar 21 at 16:38
@canton7 I don't need to escape escapes. This answer fits my needs
– Herrgott
Mar 21 at 16:38
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.
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%2f55285050%2fc-split-string-with-separator-by-regex-if-separator-is-surrounded-by-something%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
2
What do you want returned for
"Hello\.World"
?– Dour High Arch
Mar 21 at 16:29
1
(?<!\).
?– Ahmed Abdelhameed
Mar 21 at 16:30
1
You want a "negative lookbehind"
– Blorgbeard
Mar 21 at 16:30
@DourHighArch the first case. I skipped @ to make it more readable. Sorry for non-obviousness
– Herrgott
Mar 21 at 16:35