Can anyone help me with XSLT code to convert as below
Input:
123456789
12345
123
Output:
1234567.89
123.45
1.23
I used below code
<xsl:value-of select="format-number(Amount, '##.##')"/>
To convert an amount like 123 to 1.23 (and 50 to 0.50), you need to do:
format-number($amount div 100, '0.00')
Related
enter code hereI am trying to find if a text column on Big Query has phone numbers in them.
I am currently using the following code:
Input table :
text_field
Hello please call us on +1 123 456 789
Please allow 2 days for the purchase to reflect in your wallet
Code:
select
text_field
from
table
where
and REGEXP_CONTAINS(text_field, r'[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]') = True
Desired table :
text_field
Hello please call us on +1 123 456 789
However, I see many different formats of phone numbers written in many different ways. Example: +1 123 345 789, + 123-456-789 etc
Is there any general regular expression I could use to detect any phone number in the text field?
if phone numbers are separated by commas, then you can use the following regular expression '[^,]+'
If the phone numbers are not structured, then the search is difficult. Or use ^\+?[178][-\(]?\d{3}\)?-?\d{3}-?\d{2}-?\d{2}$ only I don't know if the database supports such regular expressions
how to create a regex that automatically adds a space after every 3-4 letters?
I currently have a regex created, but it will add a space only after adding a letter to the input:
function format(s) {
return s.toString().replace(/\d{3,4}?(?=..)/g, "$& ");
}
console.log(format(1234567890));
console.log(format(123456789));
console.log(format(1234567));
console.log(format(123456));
console.log(format(1234));
console.log(format(123));
So the output is like this.
123 456 7890
123 456 789
123 4567
123 456
1234
123
How to rebuild this regex so that the output is like this?
123 456 789 0
123 456 789
123 456 7
123 456
123 4
123
Thank you.
Currently, .. is requiring two characters after the match. If you want to allow one character after the match, remove one of the wildcards:
function format(s) {
return s.toString().replace(/\d{3,4}?(?=.)/g, "$& ");
}
console.log(format(1234567890));
console.log(format(123456789));
console.log(format(1234567));
console.log(format(123456));
console.log(format(1234));
console.log(format(123));
This produces the exact output you are looking for.
If you have only digits, you can also match 3 digits and assert a non word boundary after it using the pattern \d{3}\B
function format(s) {
return s.toString().replace(/\d{3}\B/g, "$& ");
}
console.log(format(1234567890));
console.log(format(123456789));
console.log(format(1234567));
console.log(format(123456));
console.log(format(1234));
console.log(format(123));
I am trying to print the lines that have numbers that are either greater or equal to 3 and less than or equal to 6. The problem is that the regular expression I have prints out the files that are 3 or more and not 3 to 6.
What I am trying to get
Valid:
123
34564
234552
Invalid:
12
1453756
What I am getting
Valid:
123
34564
234552
1453756
Invalid:
12
/[0-9]{3,6}/
I tried the following, and it worked for me :
\d{3,6}
Try to use following
^[\d]{3,6}[^\d]
It is working as specified in your requirement
I'd like to take raw input from a user and then re-arranging the output in a different order. I have the code working, but the output has single quotes around each number. Here is the really simple code:
CodeNumber=(raw_input("Please enter 4 digit number: "))
print "Code_A: %r%r%r" %(CodeNumber[3], CodeNumber[1], CodeNumber[0])
print "Code_B: %r%r%r" %(CodeNumber[2], CodeNumber[3], CodeNumber[1])
The output I get is:
Please enter 4 digit number: 1234
Code_A: '4''2''1'
Code_B: '3''4''2'
How do I remove the single quotation marks so I get 421 instead of '4''2''1'?
At least one way to do this is to use int() on element indices of CodeNumber to turn the strings into numbers.
This is your edited code (by me, hob!)
CodeNumber=(raw_input("Please enter 4 digit number: "))
print "Code_A: %r%r%r" %(int(CodeNumber[3]), int(CodeNumber[1]), int(CodeNumber[0]))
print "Code_A: %r%r%r" %(int(CodeNumber[2]), int(CodeNumber[3]), int(CodeNumber[1]))
Output:
Please enter 4 digit number: 1234
Code_A: 421
Code_B: 342
Running time = O(n)
I would like to validate a telephone number which can contain 10 to 13 digit numbers and can contain 0 to 3 spaces (can come anywhere in the data). Please let me know how to do it?
I tried using regex ^(\d*\s){0,3}\d*$ which works fine but I need to restrict the total number of characters to 13.
You want to match same text against 2 different whole-line patterns.
It's achievable either by matching patterns consequently:
$ cat file
1234567 90
1234567890
123 456 789 0123
123 456 789 01 23
$ sed -rn '/^([0-9] ?){9,12}[0-9]$/{/^([0-9]+ ){0,3}[0-9]+$/p}' file
1234567890
123 456 789 0123
$
Or if Your regex engine (perl/"grep -P"/java/etc) supports lookaheads - patterns can be combined:
// This is Java
Pattern p = Pattern.compile("(?=^([0-9] ?){9,12}[0-9]$)(?=^([0-9]+ ){0,3}[0-9]+$)^.*$");
System.out.println(p.matcher("1234567 90").matches()); // false
System.out.println(p.matcher("123 456 789 0123").matches()); // true
System.out.println(p.matcher("123 456 789 01 23").matches()); // false