just starting out with KQL, I currently have a string which is set to: "server1-Incremantal")
I am looking to remove the front '"' and trailing '")' . So effectively just reads "server1-Incremantal" (without the quotes) any help to get this done will greatly appreciated!!
I am looking to for the string to read "server1-Incremantal" (without the quotes) any help to get this done will greatly appreciated!!
you can use the parse operator.
other functions you may find helpful are:
trim_end()
trim_start()
trim()
substring()
for example:
print input = '"server1-Incremantal")'
| parse input with '"' output '")'
input
output
"server1-Incremantal")
server1-Incremantal
Related
I am working with a string column in redshift database where the instance of \" occurs multiple times in the same value.
I want to replace every occurrence of \" with "
For example, if a string = \"name\"
I want the output to be string = "name"
From what I have found, redshift does not allow the existence of a single backslash, and automatically converts it to a double backslash, but that is not happening in this case.
I have tried to use the REPLACE() with REPLACE( string, '\"', '"' ) but it did not have any effect. Can the string being a JSON string have any bearing on the function of REPLACE()?
I have been trying to use regexp_replace but maybe I am not using the right regular expression, hence I am not able to solve the problem.
REPLACE( string, '\\"', '"' ) seems works in this situation. I am guessing its because redshift doesn't allow a single backslash, but converts them to double backslash.
So, even though the string looked like \"name\" it was probably stored as \\"name\\" and hence putting a single backslash in the replace was not working.
EDIT: please read Bill's explanation in the comment below this reply
I'm fairly new to coding and I was wondering if you could give me a hand writing some regular expression for BigQuery SQL.
Basically I would like to extract everything before the bar sign "|" for one of my column.
Example:
Source string:
bla-BLABLA-cid=123456_sept1220_blabla--potato-Blah|someMore_string_stuff-IDontNeed
Desired output:
bla-BLABLA-cid=123456_sept1220_blabla--potato-Blah
I thought about using the REGEXP_EXTRACT(string, delimiter) function but I'm totally unable to write some regex (LOL). Therefore I had a look over Stack, and have found stuff like:
SELECT REGEXP_EXTRACT( String_Name , "\S*\s*\|" ) ,
# or
SELECT REGEXP_EXTRACT( String_Name , '.+?(?=|)')
But every time I get error messages like " invalid perl operator: (?= " or "Illegal escape space"
Would you have any suggestions on why I get these messages and/or how could I proceed to extract these strings?
Many many thanks in advance <3
You can use SPLIT instead:
SELECT SPLIT("bla-BLABLA-cid=123456_sept1220_blabla--potato-Blah|someMore_string_stuff-IDontNeed", "|")[OFFSET(0)]
Prefix the pattern string with r:
SELECT REGEXP_EXTRACT(String_Name, r'\S*\s*\|')
This is the syntax for a raw string constant. You can review what this means in the documentation.
I recently reached out to this community for assistance on how to remove a specific character from the very beginning of a string and at the end of a string. In my case, the character I needed removed was an ampersand. Here is the code I used that resolved my issue:
select substr((rpu.userrole), 2, length(rpu.userrole) - 2) AS UserRole
However, now I am left with strings like this after the very first and last ampersand have been removed:
BachelorLvlProvider&ShortTermAccess&WrkflwBachelorLvl
As you can see, there are anywhere between zero and several ampersands separating these role positions. Cache seems to have a lot of functions to concatenate strings, but am not having any luck finding functions to replace characters in a string. There is a "$replace" function but I believe it only works in ObjectScript.
Can anyone assist me in replacing all ampersands regardless of how many there are in each string with the literal ', ' ? I need to separate these with a single comma and one space. I included the tick marks as that are what I use in the code for my strings.
Any assistance would be greatly appreciated.
Thanks!
You can use REPLACE in SQL as well (Caché/Ensemble and IRIS).
SELECT REPLACE('BachelorLvlProvider&ShortTermAccess&WrkflwBachelorLvl','&',',') as UserRole
will give
BachelorLvlProvider,ShortTermAccess,WrkflwBachelorLvl
My test below works perfectly well :
SELECT REPLACE(substr(('&BachelorLvlProvider&ShortTermAccess&WrkflwBachelorLvl&'), 2, length('&BachelorLvlProvider&ShortTermAccess&WrkflwBachelorLvl&') - 2),'&',',') as UserRole
SSN=LTRIM(RTRIM(REPLACE(A.SSN,'-','')))
Can some one please help me? This code replaces "-" with '' of ssn column which works. But now I want to also replace dots . with '' string. Can someone help me how to replace both - and .?
Any help will be highly appreciated.
Thank you
Use one more replace
LTRIM(RTRIM(REPLACE(REPLACE(A.SSN,'-',''),'.','')))
If you are using Oracle, the easiest way to do this is using regexp_replace to only get the digits.
regexp_replace(ssn, '\D', '')
In pig script, I would like to find a way to escape the delimiter character in my data so that it doesn't get interpreted as extra columns. For example, if I'm using colon as a delimiter, and I have a column with value "foo:bar" I want that string interpreted as a single column without having the loader pick up the comma in the middle.
You can try http://pig.apache.org/docs/r0.12.0/func.html#regex-extract-all
A = LOAD 'somefile' AS (s:chararray);
B = FOREACH A GENERATE FLATTEN(REGEX_EXTRACT_ALL(s, '(.*) : (.*)'));
The regex might have to be adapted.
It seems Pig takes the Input as the string its not so intelligent to identify how what is data or what is not.
The pig Storage works on the Strong Tokenizer. So if u want to do something like
a = LOAD '/abc/def/file.txt' USING PigStorage(':');
It doesn't seems to be solving your problem. But if we can write our own PigStorage() Method possibly we could come across some solution.
I will try posting the Code to resolve this.
you can use STRSPLIT(string, regex, limit); for the column split based on the delimiter.