Skip to main content
added 113 characters in body
Source Link
Dariusz
  • 22.5k
  • 9
  • 81
  • 116

Optimization methods:

  • use Pattern.compile() for each replace. Create a class, make patterns fields, and compile the patterns only once. That way you will save a lot of time, since regex compile takes place each time you call replaceAll() and it is a very costly operation
  • use non-greedy regexes. Instead of (\\d+) use (\\d+?).
  • try to not use regexes if possible (lb.->pound)?
  • merging several regexes with the same substitutions into one - applicable to your sqkm or feet replaces
  • you could try to base your api on StringBuilder; then use addReplacement to process your text.

Moreover a dot in many of your replaces is unescaped. Dot matches any character. Use \\..

Class idea:

class RegexProcessor {
  private Pattern feet1rep = Pattern.compile("\\b(\\d+)[ ]?'[ ]?(\\d+)\"");
  // ...

  public String process(String org) {
    String mod = feet1rep.match(org).replaceAll("$1 feet $2  ");
    /...
  }
}

Optimization methods:

  • use Pattern.compile() for each replace. Create a class, make patterns fields, and compile the patterns only once. That way you will save a lot of time, since regex compile takes place each time you call replaceAll() and it is a very costly operation
  • use non-greedy regexes. Instead of (\\d+) use (\\d+?).
  • try to not use regexes if possible (lb.->pound)?
  • you could try to base your api on StringBuilder; then use addReplacement to process your text.

Moreover a dot in many of your replaces is unescaped. Dot matches any character. Use \\..

Class idea:

class RegexProcessor {
  private Pattern feet1rep = Pattern.compile("\\b(\\d+)[ ]?'[ ]?(\\d+)\"");
  // ...

  public String process(String org) {
    String mod = feet1rep.match(org).replaceAll("$1 feet $2  ");
    /...
  }
}

Optimization methods:

  • use Pattern.compile() for each replace. Create a class, make patterns fields, and compile the patterns only once. That way you will save a lot of time, since regex compile takes place each time you call replaceAll() and it is a very costly operation
  • use non-greedy regexes. Instead of (\\d+) use (\\d+?).
  • try to not use regexes if possible (lb.->pound)?
  • merging several regexes with the same substitutions into one - applicable to your sqkm or feet replaces
  • you could try to base your api on StringBuilder; then use addReplacement to process your text.

Moreover a dot in many of your replaces is unescaped. Dot matches any character. Use \\..

Class idea:

class RegexProcessor {
  private Pattern feet1rep = Pattern.compile("\\b(\\d+)[ ]?'[ ]?(\\d+)\"");
  // ...

  public String process(String org) {
    String mod = feet1rep.match(org).replaceAll("$1 feet $2  ");
    /...
  }
}
class and StringBuilder hint
Source Link
Dariusz
  • 22.5k
  • 9
  • 81
  • 116

Optimization methods:

  • use Pattern.compile() for each replace. Create a class, make patterns fields, and compile the patterns only once. That way you will save a lot of time, since regex compile takes place each time you call replaceAll() and it is a very costly operation
  • use non-greedy regexes. Instead of (\\d+) use (\\d+?).
  • try to not use regexes if possible (lb.->pound)?
  • you could try to base your api on StringBuilder; then use addReplacement to process your text.

Moreover a dot in many of your replaces is unescaped. Dot matches any character. Use \\..

Class idea:

class RegexProcessor {
  private Pattern feet1rep = Pattern.compile("\\b(\\d+)[ ]?'[ ]?(\\d+)\"");
  // ...

  public String process(String org) {
    String mod = feet1rep.match(org).replaceAll("$1 feet $2  ");
    /...
  }
}

Optimization methods:

  • use Pattern.compile() for each replace. Create a class, make patterns fields, and compile the patterns only once. That way you will save a lot of time, since regex compile takes place each time you call replaceAll() and it is a very costly operation
  • use non-greedy regexes. Instead of (\\d+) use (\\d+?).
  • try to not use regexes if possible (lb.->pound)?

Moreover a dot in many of your replaces is unescaped. Dot matches any character. Use \\..

Optimization methods:

  • use Pattern.compile() for each replace. Create a class, make patterns fields, and compile the patterns only once. That way you will save a lot of time, since regex compile takes place each time you call replaceAll() and it is a very costly operation
  • use non-greedy regexes. Instead of (\\d+) use (\\d+?).
  • try to not use regexes if possible (lb.->pound)?
  • you could try to base your api on StringBuilder; then use addReplacement to process your text.

Moreover a dot in many of your replaces is unescaped. Dot matches any character. Use \\..

Class idea:

class RegexProcessor {
  private Pattern feet1rep = Pattern.compile("\\b(\\d+)[ ]?'[ ]?(\\d+)\"");
  // ...

  public String process(String org) {
    String mod = feet1rep.match(org).replaceAll("$1 feet $2  ");
    /...
  }
}
added 138 characters in body
Source Link
Dariusz
  • 22.5k
  • 9
  • 81
  • 116

Optimization methods:

  • use Pattern.compile() for each replace. Create a class, make patterns fields, and compile the patterns only once. That way you will save a lot of time, since regex compile takes place each time you call replaceAll() and it is a very costly operation
  • use non-greedy regexes. Instead of (\\d+) use (\\d\\d+?+).
  • try to not use regexes if possible (lb.->pound)?

Moreover a dot in many of your replaces is unescaped. Dot matches any character. Use \\..

Optimization methods:

  • use Pattern.compile() for each replace. Create a class, make patterns fields, and compile the patterns only once.
  • use non-greedy regexes. Instead of (\\d+) use (\\d?+).
  • try to not use regexes if possible (lb.->pound)?

Moreover a dot in many of your replaces is unescaped. Dot matches any character. Use \\..

Optimization methods:

  • use Pattern.compile() for each replace. Create a class, make patterns fields, and compile the patterns only once. That way you will save a lot of time, since regex compile takes place each time you call replaceAll() and it is a very costly operation
  • use non-greedy regexes. Instead of (\\d+) use (\\d+?).
  • try to not use regexes if possible (lb.->pound)?

Moreover a dot in many of your replaces is unescaped. Dot matches any character. Use \\..

Source Link
Dariusz
  • 22.5k
  • 9
  • 81
  • 116
Loading