We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Why the parser fails to parse the RegEx into document for JAVA

Dear Support,
Why the parser fails to parse the RegEx into document for JAVA?

Tested with 18.10 aspose words for java.
ASNIPA.docx.zip (61.7 KB)

The use case is as follow.
We have texts that are AI parsed data with certain normalization of text. So, there is chances that some extra spaces may be added. To parse correctly, I have used regular expression as mentioned.

public static void main11(String[] args) {
		try{
			Document doc = new Document("ASNIPA.docx");
			FindReplaceOptions op = new FindReplaceOptions(FindReplaceDirection.FORWARD);
			op.setFindWholeWordsOnly(false);
			op.setMatchCase(false);

			op.setReplacingCallback(new IReplacingCallback() {
				@Override
				public int replacing(ReplacingArgs e) throws Exception {
					System.out.println("called");
					return ReplaceAction.SKIP;
			    }
			} );
			
			doc.getRange().replace(Pattern.compile("Email\\s{1,}–\\s{1,}mamadzni@yahoo\\.com"), "", op);
		}catch(Exception e){
			e.printStackTrace();
		}
	}

@ganesh.sv

Thanks for your inquiry. We have tested the scenario and have managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-17918. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

@tahir.manzoor How long would it take to release the issue fix?

@ganesh.sv

Thanks for your inquiry. We try our best to deal with every customer request in a timely fashion, we unfortunately cannot guarantee a delivery date to every customer issue. We work on issues on a first come, first served basis. We feel this is the fairest and most appropriate way to satisfy the needs of the majority of our customers.

We will inform you via this forum thread once there is an update available on this issue. As a workaround, please use following code example. Hope this helps you.

Document doc = new Document(MyDir + "ASNIPA.docx");

FindReplaceOptions op = new FindReplaceOptions(FindReplaceDirection.FORWARD);
op.setFindWholeWordsOnly(false);
op.setMatchCase(false);

// Build string to replace text and next field.
FieldStart fieldStart = (FieldStart)doc.getChild(NodeType.FIELD_START, 0, true);
Field field = fieldStart.getField();
String fieldCode = field.getFieldCode();
String result = field.getResult();

String searchPattern = "Email – " + fieldCode + result;
searchPattern = Pattern.quote(searchPattern);

Pattern regexPattern = Pattern.compile(searchPattern);
System.out.println(doc.getRange().replace(regexPattern, "", op));

doc.save(MyDir + "18.12.java.docx");

You reported this issue in free support forum and it will be treated with normal priority. To speed up the progress of issue’s resolution, we suggest you please check our paid support policies from following link.
Paid Support Policies