How to keep the delimiters of Regex.Split?

Just put the pattern into a capture-group, and the matches will also be included in the result. string[] result = Regex.Split(“123.456.789″, @”(\.)”); Result: { “123”, “.”, “456”, “.”, “789” } This also works for many other languages: JavaScript: “123.456.789”.split(/(\.)/g) Python: re.split(r”(\.)”, “123.456.789”) Perl: split(/(\.)/g, “123.456.789”) (Not Java though)

Lua need to split at comma

Try this str=”cat,dog” for word in string.gmatch(str, ‘([^,]+)’) do print(word) end ‘[^,]’ means “everything but the comma, the + sign means “one or more characters”. The parenthesis create a capture (not really needed in this case).

How to split string across new lines and keep blank lines?

I’d recommend using lines instead of split for this task. lines will retain the trailing line-break, which allows you to see the desired empty-line. Use chomp to clean up: “aaaa\nbbbb\n\n”.lines.map(&:chomp) [ [0] “aaaa”, [1] “bbbb”, [2] “” ] Other, more convoluted, ways of getting there are: “aaaa\nbbbb\n\n”.split(/(\n)/).each_slice(2).map{ |ary| ary.join.chomp } [ [0] “aaaa”, [1] “bbbb”, … Read more

Split a string based on multiple delimiters

escape needed for regex related characters +,-,(,),*,? var x = “adfds+fsdf-sdf”; var separators = [‘ ‘, ‘\\\+’, ‘-‘, ‘\\\(‘, ‘\\\)’, ‘\\*’, “https://stackoverflow.com/”, ‘:’, ‘\\\?’]; console.log(separators.join(‘|’)); var tokens = x.split(new RegExp(separators.join(‘|’), ‘g’)); console.log(tokens); http://jsfiddle.net/cpdjZ/

C# Regex Split – everything inside square brackets

Split won’t help you here; you need to use regular expressions: // using System.Text.RegularExpressions; // pattern = any number of arbitrary characters between square brackets. var pattern = @”\[(.*?)\]”; var query = “H1-receptor antagonist [HSA:3269] [PATH:hsa04080(3269)]”; var matches = Regex.Matches(query, pattern); foreach (Match m in matches) { Console.WriteLine(m.Groups[1]); } Yields your results.

String split on new line, tab and some number of spaces

Just use .strip(), it removes all whitespace for you, including tabs and newlines, while splitting. The splitting itself can then be done with data_string.splitlines(): [s.strip() for s in data_string.splitlines()] Output: >>> [s.strip() for s in data_string.splitlines()] [‘Name: John Smith’, ‘Home: Anytown USA’, ‘Phone: 555-555-555’, ‘Other Home: Somewhere Else’, ‘Notes: Other data’, ‘Name: Jane Smith’, ‘Misc: … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)