Question

Given,

    $string1 = "Reference: AbcDef   PO: 12345abC   line: 01";

    $string1 = "Reference: AbcDef   po: 12345abC   line: 01";

The idea here is to extract the value after "PO:" or "po:" and before "line" using XPath and/ or RegEx.

Usually, this is how I would do it, substring-after(upper-case(string1), "PO:"). This will cater both PO: and po:; but this will also affect the result which is all in uppercase, "12345ABC".

The question here, how can I extract the value without affecting the outcome.

In perl, there is "?i" meaning regardless upper-case or lower-case.

Any help would be greatly appreciated.

Was it helpful?

Solution

If you can use regex, I suppose that you could use something like this

substring-after(string1, (PO:|po:))

where the regular expression match with one of the options. Take care with this if before the po: or PO: what you want to match, there is another substring which also match.

OTHER TIPS

You can use fn:replace and a regular expression to extract the value of the PO or po field and discard the rest of the string:

replace($string1, ".*(?:PO:|po:)\s(.*)line.*", "$1")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top