string
[] result= Regex.Split(str,
"
$"
);
but it is not splitting ..When i tried splitting by # then it works.
What I have tried:
string
str =
"
12$34$45"
;
string
[] result= Regex.Split(str,
"
$"
);
Because '$' is a special meaning in a RegEx, knowing this is regEx 101.
you need to escape it as @"\$"
Just a few interesting links to help building and debugging RegEx.
Here is a link to RegEx documentation:
perlre - perldoc.perl.org
[
^
]
Here is links to tools to help build RegEx and debug them:
.NET Regex Tester - Regex Storm
[
^
]
Expresso Regular Expression Tool
[
^
]
RegExr: Learn, Build, & Test RegEx
[
^
]
This one show you the RegEx as a nice graph which is really helpful to understand what is doing a RegEx:
Debuggex: Online visual regex tester. JavaScript, Python, and PCRE.
[
^
]
string[] result = Regex.Split(str,
"
[$]"
);
The operator [ ] represents a class of characters, so the regex trys to match all that is inside these brackets.
For multiple $ (2 in this case):
string[] result = Regex.Split(str,
"
[$]{2}"
);
Read the question carefully.
Understand that English isn't everyone's first language so be lenient of bad
spelling and grammar.
If a question is poorly phrased then either ask for clarification, ignore it, or
edit the question
and fix the problem. Insults are not welcome.
Don't tell someone to read the manual. Chances are they have and don't get it.
Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
string str = "12$$34$$45";
string [] result= Regex.Split(str, @"\$$");
it doesn't work. How to handle this?
Actually i want to split my string and separator may be of multiple characters.
e.g.:
string str = "12$$34$$45";
string separator = "$~$";
string [] result= Regex.Split(str, @"\"+ separator + "");