[Solved] Why there are empty string while trying to split a string in Java? And how to fix it?

It’s because you’re splitting by a single character, you would have to do this eagerly: String[] Operators = stringNumbers.split(“[0-9.]*”); Or you can filter the results: String[] Operators = Arrays.stream(stringNumbers.split(“[0-9.]”)) .filter(str -> !str.equals(“”)) .toArray(String[]::new); 5 solved Why there are empty string while trying to split a string in Java? And how to fix it?

[Solved] find substring using match regex

Since this is not quite HTML and any XML/HTML parser couldn’t help it you can try with regex. It seems that you want to find text in form ?drug <someData> ?disease To describe such text regex you need to escape ? (it is one of regex special characters representing optional – zero or once – … Read more

[Solved] Simple regex – parse Firstname Lastname, sex (male,female), age or birth year

You only want “name, sex, age(or YearOfBirth)” You still can use Regex for it, or String.Split: Split solution: string line = “Max Smith m 20″; string[] words = line.Split(” “); int nr = items[words.Length – 1]; //use number to determine age or year string gender = items[words.Length – 2]; //string name = combine the leftover … Read more

[Solved] Remove all symbols different from numbers and letters in string [duplicate]

This should work: var result = new Regex(“[^a-zA-Z0-9 ]”).Replace(address, string.Empty); This keeps only whatever in a-Z, A-Z or 0-9 or white space You can also use linq: var result2 = new String(address.Where(x => char.IsLetterOrDigit(x) || char.IsWhiteSpace(x)).ToArray()); 4 solved Remove all symbols different from numbers and letters in string [duplicate]

[Solved] Getting the substring after a character in C# using regex

In C#, use Substring() with IndexOf: string val = val.Substring(val.IndexOf(‘]’) + 1); If you have multiple ] symbols, and you want to get all the string after the last one, use LastIndexOf: string val = “[01/02/70]\nhello [01/02/80] world “; string val = val.Substring(val.LastIndexOf(‘]’) + 1); // => ” world ” If you are a fan … Read more

[Solved] Write regular expressions [closed]

I would suggest something like this: /\) (?!.*\))(\S+)/ rubular demo Or if you don’t want to have capture groups, but potentially slower: /(?<=\) )(?!.*\))\S+/ rubular demo (?!.*\)) is a negative lookahead. If what’s inside matches, then the whole match will fail. So, if .*\) matches, then the match fails, in other terms, it prevents a … Read more

[Solved] Getting string between exact letters by regex in Swift

As per my comment, this is a task for DateFormatter rather than RegeX. I threw this together in a playground quickly to demonstrate what I mean. let inFormatter = DateFormatter() inFormatter.locale = Locale(identifier: “en_US_POSIX”) inFormatter.dateFormat = “yyyy-MM-dd’T’HH:mm:ssZZZZZ” let input = “2019-03-11T17:04:00+0100” let dateFromInput = inFormatter.date(from: input)! // This should be unwrapped properly in your code. … Read more