Linked Questions

2 votes
0 answers
59 views

Consider the following program (it can be compiled and run online e. g. at Javatpoint): public class Simple { public static void main(String args[]) { System.out.println("A:B:C:D&...
Armali's user avatar
  • 19.6k
78 votes
7 answers
4k views

So, some way or another (playing around), I found myself with a regex like \d{1}{2}. Logically, to me, it should mean: (A digit exactly once) exactly twice, i.e. a digit exactly twice. But it, in ...
Bernhard Barker's user avatar
57 votes
4 answers
9k views

Given: String input = "one two three four five six seven"; Is there a regex that works with String.split() to grab (up to) two words at a time, such that: String[] pairs = input.split("some regex"); ...
Bohemian's user avatar
  • 427k
15 votes
3 answers
41k views

Is this the proper REGEX to remove trailing decimal and zeroes from a string? I can't get it to work. What am I missing? 78.000 -> 78 78.008 -> 78.008 str.replaceAll("^.0*$", "");
Cody's user avatar
  • 9,004
23 votes
1 answer
7k views

This is the third part in a series of educational regex articles. It follows How does this regex find triangular numbers? (where nested references is first introduced) and How can we match a^n b^n ...
polygenelubricants's user avatar
2 votes
5 answers
5k views

I would like some guidance on how to split a string into N number of separate strings based on a arithmetical operation; for example string.length()/300. I am aware of ways to do it with delimiters ...
Carlos's user avatar
  • 5,475
5 votes
3 answers
13k views

I'm trying to use regex to find a particular starting character and then getting the rest of the text on that particular line. For example the text can be like ... V: mid-voice T: tempo I want to ...
user941401's user avatar
3 votes
2 answers
9k views

I need to replace the duplicate characters in a string. I tried using outputString = str.replaceAll("(.)(?=.*\\1)", ""); This replaces the duplicate characters but the position of the characters ...
Johny's user avatar
  • 2,186
2 votes
5 answers
5k views

I want to skip first occurrence if no of occurrence more than 4. For now I will get max of 5 number underscore occurrence. I need to produce the output A_B, C, D, E, F and I did using below code. I ...
Abdul's user avatar
  • 1,050
1 vote
3 answers
3k views

I need a regular expression that matches the second "abc" in "abcasdabchjkabc". I attempt to write code like this, Pattern p = Pattern.compile("(?<=abc(.*?))abc"); but it throws a java.util.regex....
miaowhehe's user avatar
  • 651
4 votes
2 answers
408 views

I am splitting a string by a repeatable delimiter, and am also intended to keep the delimiters as well. val str = "xxoooooooxxoxoxooooo" val reg = Regex("(?<=x+)|(?=x+)") var ...
Mark's user avatar
  • 6,554
11 votes
1 answer
874 views

I have the following Java SE code, which runs on PC public static void main(String[] args) { // stringCommaPattern will change // ","abc,def"," // to // ","abcdef"," ...
Cheok Yan Cheng's user avatar
1 vote
2 answers
1k views

Given a string containing some number of square brackets and other characters, I want to find all closing square brackets preceded by an opening square bracket and some number of letters. For instance,...
David Moles's user avatar
  • 51.7k
0 votes
1 answer
2k views

I have a regex to detect any email address - I am trying to create a regex that looks specifically in the header of an email message that counts email addresses and ignores email addresses from a ...
user1181862's user avatar
3 votes
2 answers
437 views

Using Java and regex, I want to extract strings from a line of text. The text can be in following format - key1(value1) key2(value2) key1(value1) key2 key1 key2(value2) key1 key2 key1 Am successfully ...
Prasoon's user avatar
  • 445

15 30 50 per page