0

I need regex expression that will replace all suffix "SJD" not preceded by prefix "/" to "OZPS" (and it must work with ant builder).

I cut few lines from my xml file with example occurrences:

input:

<replaceregexp flags="g" match="SJD" replace="OZPS" file="../ozps/build.xml"/>
<replaceregexp flags='g' match='"\/CAS\/SJD"' replace='"/CAS/OZPS"'>
<replaceregexp flags="g" match="SJD" replace="OZPS">

expected output:

<replaceregexp flags="g" match="OZPS" replace="OZPS" file="../ozps/build.xml"/>
<replaceregexp flags='g' match='"\/CAS\/SJD"' replace='"/CAS/OZPS"'>
<replaceregexp flags="g" match="OZPS" replace="OZPS">

I tried negative lookbehind assertion buit it seems not work.

EDIT: Small explanation for each who works with online regex testers. Most of them do not support negative lookbehind assertion because of java script regexp engine. Unlike JS, java engine seems to support NLA so if you test expression's dedicated for java I recommend to use this https://regex101.com

1 Answer 1

1

You could try something like so: (?<!\/)SJD.

An example is available here.

EDIT: Looking at this question, it would seem that you could do this:

<replaceregex pattern="(?&lt;!\/)SJD" replace="OZPS"
    flags="gis" byline="false"/>

EDIT: < will need to be replaced by &lt; to escape it from the remainder of the XML file, as per @Piotr's recommendation.

Sign up to request clarification or add additional context in comments.

7 Comments

Thanks for comment. I tried something like this here: regexr.com and here: regexpal.com And it doesn't work. But it seems like javascript doesn't support negative lookbehind assertion. I'am not sure how regex is implemented in ant but i suppose it's based on java so let's try!
@PiotrZych: The link you have posted provides no information on the regular expression you have tried. Maybe you could use the regex101 site and provide a link from there?
I tried the same as you pasted but these sites do not support pasting&linking.
@PiotrZych: Would it be possible to edit your question and paste the regular expression you have used?
Wait a minute i will try your solution with real ant. Project is building very long (about 8 minutes), so i was not able to try every expression. If it will be ok i will close this thread. In other case i will paste all solution, that i tested.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.