Skip to content

Commit

Permalink
match to exact pattern so that can remove a replaceAll
Browse files Browse the repository at this point in the history
  • Loading branch information
kuronekochomusuke committed Sep 4, 2023
1 parent e462e7b commit 40d336c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions megamek/src/megamek/client/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -1210,12 +1210,12 @@ public String receiveReport(Vector<Report> v) {

Set<Integer> setEntity = new HashSet<>();
//find id stored in spans and extract it
Pattern pEntity = Pattern.compile("<span id=(.*?)></span>");
Pattern pEntity = Pattern.compile("<span id='(.*?)'></span>");
Matcher mEntity = pEntity.matcher(report.toString());

// add all instances to a hashset to prevent duplicates
while (mEntity.find()) {
String cleanedText = mEntity.group(1).replaceAll("[^\\d-]", "");
String cleanedText = mEntity.group(1);
if (!cleanedText.isBlank()) {
try {
setEntity.add(Integer.parseInt(cleanedText));
Expand All @@ -1234,7 +1234,7 @@ public String receiveReport(Vector<Report> v) {

Set<String> setCrew = new HashSet<>();
//find id stored in spans and extract it
Pattern pCrew = Pattern.compile("<span crew=(.*?)></span>");
Pattern pCrew = Pattern.compile("<span crew='(.*?)'></span>");
Matcher mCrew = pCrew.matcher(report.toString());

// add all instances to a hashset to prevent duplicates
Expand All @@ -1247,7 +1247,7 @@ public String receiveReport(Vector<Report> v) {

// loop through the hashset of unique ids and replace the ids with img tags
for (String tmpCrew : setCrew) {
String[] crewS = tmpCrew.replaceAll("'", "").split(":");
String[] crewS = tmpCrew.split(":");
int entityID = -1;
int crewID = -1;

Expand Down

0 comments on commit 40d336c

Please sign in to comment.