I am using ui-mask="AA/AAA/9999999/999/9999999" in my angularjs to read PF number
the format will be Format : (Region Code/Office Code/Est Code/Extn No/Member Acc No) Example HR/FBD/0003256/000/0000125.
Now, istead of Extn No 000 i need to allow alphanumeric like 000,00A,00R for last chanracter.how to do it pls suggest.
Related
I currently have select REGEXP_LIKE(col, '[0-9]+') which seems to return True only if all the characters in the string are numeric.
For example, it returns True for 12345 but False for something like 100 Apple St.
What is the necessary regex pattern to return True in both examples above?
To check if a column contains any digit, you can modify your current pattern to use the .* character to match any number of characters before or after the digit(s):
SELECT REGEXP_LIKE(col, '.*[0-9].*')
I would like to check if a specific column in one of my tables meets the following conditions:
String must contain at least three characters
String must contain at least two different numbers [e.g. 123 would work but 111 would not]
Characters which are allowed in the string:
Numbers (0-9)
Uppercase letters
Lowercase letters
Underscores (_)]
Dashes (-)
I have some experience with Regex but am having issues with Snowflake's syntax. Whenever I try using the '?' regex character (to mark something as optional) I receive an error. Can someone help me understand a workaround and provide a solution?
What I have so far:
SELECT string,
LENGTH(string) AS length
FROM tbl
WHERE REGEXP_LIKE(string,'^[0-9]+{3,}[-+]?[A-Z]?[a-z]?$')
ORDER BY length;
Thanks!
Your regex looks a little confusing and invalid, and it doesn't look like it quite meets your needs either. I read this expression as a string that:
Must start with one or more digits, at least 3 or more times
The confusing part to me is the '+' is a quantifier, which is not quantifiable with {3,} but somehow doesn't produce an error for me
Optionally followed by either a dash or plus sign
Followed by an uppercase character zero or one times (giving back as needed)
Followed by and ending with a lowercase character zero or one times (giving back as needed)
Questions
You say that your string must contain 3 characters and at least 2 different numbers, numbers are characters but I'm not sure if you mean 3 letters...
Are you considering the numbers to be characters?
Does the order of the characters matter?
Can you provide an example of the error you are receiving?
Notes
Checking for a second digit that is not the same as the first involves the concept of a lookahead with a backreference. Snowflake does not support backreferences.
One thing about pattern matching with regular expressions is that order makes a difference. If order is not of importance to you, then you'll have multiple patterns to match against.
Example
Below is how you can test each part of your requirements individually. I've included a few regexp_substr functions to show how extraction can work to check if something exists again.
Uncomment the WHERE clause to see the dataset filtered. The filters are written as expressions so you can remove any/all of the regexp_* columns.
select randstr(36,random(123)) as r_string
,length(r_string) AS length
,regexp_like(r_string,'^[0-9]+{3,}[-+]?[A-Z]?[a-z]?$') as reg
,regexp_like(r_string,'.*[A-Za-z]{3,}.*') as has_3_consecutive_letters
,regexp_like(r_string,'.*\\d+.*\\d+.*') as has_2_digits
,regexp_substr(r_string,'(\\d)',1,1) as first_digit
,regexp_substr(r_string,'(\\d)',1,2) as second_digit
,first_digit <> second_digit as digits_1st_not_equal_2nd
,not(regexp_instr(r_string,regexp_substr(r_string,'(\\d)',1,1),1,2)) as first_digit_does_not_appear_again
,has_3_consecutive_letters and has_2_digits and first_digit_does_not_appear_again as test
from table(generator(rowcount => 10))
//where regexp_like(r_string,'.*[A-Za-z]{3,}.*') // has_3_consecutive_letters
// and regexp_like(r_string,'.*\\d+.*\\d+.*') // has_2_digits
// and not(regexp_instr(r_string,regexp_substr(r_string,'(\\d)',1,1),1,2)) // first_digit_does_not_appear_again
;
Assuming the digits need to be contiguous, you can use a javascript UDF to find the number in a string with with the largest number of distinct digits:
create or replace function f(S text)
returns float
language javascript
returns null on null input
as
$$
const m = S.match(/\d+/g)
if (!m) return 0
const lengths = m.map(m=> [...new Set (m.split(''))].length)
const max_length = lengths.reduce((a,b) => Math.max(a,b))
return max_length
$$
;
Combined with WHERE-clause, this does what you want, I believe:
select column1, f(column1) max_length
from t
where max_length>1 and length(column1)>2 and column1 rlike '[\\w\\d-]+';
Yielding:
COLUMN1 | MAX_LENGTH
------------------------+-----------
abc123def567ghi1111_123 | 3
123 | 3
111222 | 2
Assuming this input:
create or replace table t as
select * from values ('abc123def567ghi1111_123'), ('xyz111asdf'), ('123'), ('111222'), ('abc 111111111 abc'), ('12'), ('asdf'), ('123 456'), (null);
The function is even simpler if the digits don't have to be contiguous (i.e. count the distinct digits in a string). Then core logic changes to:
const m = S.match(/\d/g)
if (!m) return 0
const length = [...new Set (m)].length
return length
Hope that's helpful!
I would like to know how to convert this value to ArrayList?
${doc1}= Open Excel Document filename=${OpenExcel} doc_id=doc1
${view_bicccicmdu}= Read Excel Row row_num=1 max_num=6 sheet_name=UpperTT
${view_bicccicmduCheckLength}= Get Length ${view_bicccicmdu}
${HG}= Get Text ${ClickAV.CheckColumn}
${HGLenght}= Get Line Count ${HG}
Should Be Equal ${HGLenght} ${view_bicccicmduCheckLength}
Should Contain ${HG} ${view_bicccicmdu} ignore_case=True
Close Excel Document
But the result is
${HG} = Nodename
Transdate
BICC Support FAX Detection
Trunk Group Number
Bill Trunk Group Number
MGW Name Trunk
Group Name
Sub-Route Name
Circuit Type
Group Direction
Circuit Selection Mode
I need to convert it to be ArrayList and should count to be 11 Records, What should I do?
You can use the String Library and Split the string using \n as your separator, because in your case your data is separated by a line break, You can split the string into a list.
Splits the string using separator as a delimiter string.
If a separator is not given, any whitespace string is a separator. In
that case also possible consecutive whitespace as well as leading and
trailing whitespace is ignored.
Split words are returned as a list. If the optional max_split is
given, at most max_split splits are done, and the returned list will
have maximum max_split + 1 elements
You can do the following.
*** Test Cases ***
Test
${HG} = Set Variable Nodename\n ransdate\n ICC Support FAX Detection\n Trunk Group Number\n Bill Trunk Group Number\n MGW Name Trunk\n Group Name\n Sub-Route Name\n Circuit Type\n Group Direction\n Circuit Selection Mode\n
#{words} = Split String ${HG} \n
${HGLenght}= Get length ${words}
log ${words}
Results
${HGLenght} = 11
${words} = ['Nodename', 'ransdate', 'ICC Support FAX Detection', 'Trunk Group Number', 'Bill Trunk Group Number', 'MGW Name Trunk', 'Group Name', 'Sub-Route Name', 'Circuit Type', 'Group Direction', 'Circuit Selection Mode']
Hope This Helps
Thank you again, #WojTek T
My final code is
`${HG}= Get Text ${ClickAV.CheckColumn}
#{words} = Split String ${HG} \n
${UPPER1}= Evaluate "${words}".upper()
${UPPER2}= Evaluate "${view_dnc}".upper()
${HGLenght}= Get Line Count ${HG}
Should Be Equal ${HGLenght} ${view_dncCheckLength}
Should Contain ${UPPER1} ${UPPER2}`
I try to use "Get List Item" with Table name but It doesn't work, I should do this solution for my last question that I asking u. haha
Thank you again.
How can I put the text "100.000" in a table in Anychart? When I try to get the string "100.000" in, it is modified to "100".
For a working example see https://jsfiddle.net/Republiq/xcemvm9L/
table = anychart.standalones.table(2,2);
table.getCell(0,0).content("100.000");
table.container("container").draw();
If you want to use such number formatting for the whole table you can define numberLocale in the beginning. If the actual number is 100 and '.' - is a decimal separator and you want to show 3 zeros as decimals, put the following lines before creating the table:
anychart.format.locales.default.numberLocale.decimalsCount = 3;
anychart.format.locales.default.numberLocale.zeroFillDecimals = true;
And then put in the number as:
table.getCell(0,0).content(100);
If '.' - is a group separator and the actual number is 100000, put the following line:
anychart.format.locales.default.numberLocale.groupsSeparator = '.';
And then put in the number as:
table.getCell(0,0).content(100000);
If you want to use special format only for a single cell, we recommend you to use number formatter, which helps to configure all these options only for a single number. For example, it may looks like:
table = anychart.standalones.table(5,5);
table.getCell(0,0).content(anychart.format.number(100000, 3, ".", ","));
table.container("container").draw();
Also, you may learn more about this useful method and find examples in this article
I wanted read a text file in C and I want to perform search on this file. This is the content of the text file:
(EDIT: The original format looks a bit different as there are no newlines in the file. It has been reformatted to remove the whitespace between the text strings and filtered through a multicolumn program for a 80col screen.)
^%1~3~31225~2999 ^%1~8~33983~5304
~MAC100 ~MAC100
~RAJU ~LATHA CHERIAN
CR ~ELIM VILLA
~CHEMPOLA ~1
~VT : 2999 ~9847569922
~9847569922 ~32166
~29408 ~Message for bill gro~1960.0
~Message for bill gro~750.0 ~160.0
~250.0 ~0.0
~0.0 ~1~scheme name
~1~scheme name ~0
~0 ~June
~June ~VA019_95784~-
~VA019_93159~- ~0.0
~0.0 ~0~amc date 1~amc date 2~990
~1~amc date 1~amc date 2~990 ~15.0
~15.0 ~150.0
~150.0 ~narration
~narration ^%1~9~31588~3235
^%1~5~30882~2496 ~MAC100
~MAC100 ~BABU
~VISWAMPARAN T. P. ~NADUMPARMBIL
~THALAKOTTUCHALIL ~0
~C 4771 ~9847569922
~9847569922 ~29771
~29065 ~Message for bill gro~3304.0
~Message for bill gro~4320.0 ~160.0
~160.0 ~0.0
~0.0 ~1~scheme name
~1~scheme name ~0
~0 ~June
~June ~VA019_93516~-
~VA019_92833~- ~0.0
~0.0 ~0~amc date 1~amc date 2~990
~0~amc date 1~amc date 2~990 ~15.0
~15.0 ~150.0
~150.0 ~narration
~narration ^?
This is database in format of billing system. I want to do a generic search function this file based on the name and the id (which is the ^%1~9~**31588**~3235, here 31588 like that). This is file of records. Each record are begin with ^%1.~ the ~ is used to separate column values of each record. The first and last characters are not needed (^%1 in of each records and ^? at last of the file). Please help me to do this.
You first should define (or understand) precisely your input format (what are the possible & forbidden characters), perhaps using some EBNF notation.
Then you could process your input line by line (using fgets or getline) and parse each line individually (using sscanf or strtol and extra manual parsing)
Read Line by Line using fgets(), and then tokenize using strtok on the basis "~". hope that works