Search code examples
javaregexswinglistjtextarea

JTextArea regex and ordered lists


I'm having a slight problem with regex I'm trying to use on my JTextArea. What I'm trying to do it write a regex that will ignore any ordered lists and print the text area contents to the console. The lists are structured with the following conventions:

  • Begins on a new line.
  • Starts with a digit.
  • Followed with a full stop.
  • Followed by a space or a tab.

So far this is the code I'm using:

String content = txt.getText();
String removeOrderdList = content.replaceAll("^(\\d+).[ \t]+", "");

It works great on the first line of the text area contents but not on the other lines. I could remove the "^" but this will effect normal lines that have sentences


Solution

  • Use this

    String content = txt.getText();
    String removeOrderdList = content.replaceAll("(?m)^\\d+\.[ \t]+", "");