XSLT transformation: Substring after a last special character - xslt

I have fields "commercial register code: 1111111" and "commercial register code 2222" I need to take after last space symbols: 1111111 and 2222. There is function to take symbolrs before "space" in xsl?
Regards
Update from comments
I will have "comercial register 21
code:" line
And
"code" can be without ":" symbol

If there is going to be one and only one number, then you could use
translate($string,transtale($string,'0123456789',''),'')
This will remove any not digit character from the string.
If the prefixed label is stable, then you could use something like:
substring-after($string,'commercial register code:')
Abour the question:
There is function to take symbolrs before "space" in xsl?
Answer: Yes, substring-before() function
Update
From comments, it looks like the string pattern would be:
'commercial register' number 'code' (':')? number
Then use:
translate(substring-after($string,'code'), ': ', '')

In XSLT 2.0, use tokenize($in, '\s+')[last()]
If you're stuck with 1.0, you need a recursive template: check out str:tokenize in the EXSLT library.

Can you use EXSLT functions? If so, there is a str:split function and then you can do:
str:split($string, ' ')[position()=last()]

Related

Removing extra zeros concatenated with the number in XSLT

I'm working with XSLT and trying to remove all zeros present before and after the numbers.
Examples:
000000004552000 needs to translate to 4552.
Any ideas how to get this done using xslt? Thanks in advance!
Please always say what XSLT version you are using.
In 2.0, you can use replace(num, '^0+|0+$', '').
In 1.0, it's more difficult (everything is).
To remove leading zeroes, use string(number(.)).
To remove trailing zeroes, I think you need a recursive named template with the logic:
if $param mod 10 = 0
then call yourself with param = $param div 10
else $param

Regex to get values combined with "-" or "/" in Java

I want to get some element in address string for example
"Örnek Mah. Deneme Sk. No:24/8 Ankara"
an address can be like this and i want to get 24/8 or it can combined with '-' also some combination of combined values
"b-10","b/150","1256-b"
digit part can be more than one but char part is only one letter.
thanx for your help...
You can use this pattern
(\d+[/-]\d+)|(\w+[/-]\w+)

Regex to select text outside of underscores

I am looking for a regex to select the text which falls outside of underscore characters.
Sample text:
PartIWant_partINeedIgnored_morePartsINeedIgnored_PartIwant
Basically I need to be able to select the first keyword which is always before the first underscore and the last keyword which is always after the last underscore. As an additional complexity, there case also be texts which have no underscore at all, these need to be selected completely as well.
The best I got yet was this expression:
^((?! *\_[^)]*\_ *).)*
which is only yielding me the first part, not the second and it has no support for the non-underscore yet at all.
This regex is used in a tool which monitors our http traffic, which means I can only 'select' the part I need but can't invoke functions or replace logic.
Thanks!
Use JavaScript string function split(). Check below example.
var t = "PartIWant_partINeedIgnored_morePartsINeedIgnored_PartIwant";
var arr = t.split('_');
console.log(arr);
//Access the required parts like this
console.log(arr[0] + ' ' + arr[arr.length - 1]);
Perhaps something like this:
/(^[^_]+)|([^_]+$)/g
That is, match either:
^[^_]+ the beginning of the string followed by non-underscores, or
[^_]+$ non-underscores followed by the end of the string.
var regex = /(^[^_]+)|([^_]+$)/g
console.log("A_b_c_D".match(regex)) // ["A", "D"]
console.log("A_b_D".match(regex)) // ["A", "D"]
console.log("A_D".match(regex)) // ["A", "D"]
console.log("AD".match(regex)) // ["AD"]
I'm not sure if you should use a regex here. I think splitting the string at underscore, and using the first and last element of the resulting array might be faster, and less complicated.
Trivial with .replace:
str.replace(/_.*_/, '')
// "PartIWantPartIwant"
With matching, you'd need to be selecting and concatenating groups:
parts = str.match(/^([^_]*).*?([^_]*)$/)
parts[1] + parts[2]
// "PartIWantPartIwant"
EDIT
This regex is used in a tool which monitors our http traffic, which means I can only 'select' the part I need but can't invoke functions or replace logic.
This is not possible: a regular expression cannot match a discontinuous span.

Substring in DataWeave up to the occurrence of a character

In DataWeave, how would I substring an input value such that the output is everything up to the occurrence of a character? My input value is something like ABCD_123 and I need to take everything up to the underscore, so my output would be ABCD. The regex that achieves this is /[^_]*/, but I can't find a way to implement this using DataWeave. Any help would be appreciated!
Based on #WiktorStribiżew's comment, the way I solved this was by declaring a function:
%function split(text) text splitBy "_"
And then in my DW mapping, I take the value as:
OUTPUT: split(payload.INPUT)[0]

Removing ending alpha characters from string in XSLT

I have one requirement related to XSLT.
i want to remove ending alphabets in my final output string.
here is the example:
Input string:0123467AAA
Output :0123467
i.e no ending alphbets.
i m new to xslt creation,any suggestion is very helpful to me.
Thank you all in advance.
With XSLT 1.0 your only real option for this is to write a recursive template. Write a named template that takes the string as a parameter. Test whether the last character is a letter. (You can find the last character by using substring($s, string-length($s)-1, 1), and you can test whether it is a letter by testing translate($s, 'ABCD..XYZ', '') = ''). If the last character is a letter make a recursive call to your template passing the whole string minus the last character as the value of the parameter (again, by using substring()). Otherwise, return the string. Make sure that your recursion terminates if the string is zero length.