I am working on SAP NetWeaver 7.5 and having the following string
/InstrId/**BTXXXXXXXXX**/ /EndToEndId/REF 2102231XX4/ /BICFI/XXXXXRAAXXX/
I need to get as a result BTXXXXXXXXX which should also be not more than 16 characters.
I have tried ^/InstrId/(.*)/$
But I get BTXXXXXXXXX/ /EndToEndId/REF 2102231XX4/ /BICFI/XXXXXRA AXXX.
Obviously * is greedy, so I tried ^/InstrId/(.*?)/$, but I get an error that the expression is not valid.
You could change the
.*to a negated character class[^/]*not crossing matching/If you have to match the whole line, then you can use
.*and end the pattern with a forward slash at the end.The pattern matches:
^/Match/at the start of the stringInstrId/Match literally([^/]{1,16})Capture group 1, match 1-16 chars other than/.*Match the rest of the line/$Match/at the end of the lineSee a regex demo