How to remove \n���� from a sentence in bigquery - google-bigquery

I want to remove \n���� from a sentence in biquery. I have used the following query REGEXP_REPLACE(Sentence, r'([^\p{ASCII}]+)', '') AS Senetnce. It is removing only the question marks. How do I remove \n also? Thanks.

try below
select regexp_replace(Sentence, r'\n|[^\p{ASCII}]+', '')
if apply to your Question's title How to remove \n���� from a sentence in bigquery - output is

Related

Snowflake SQL - Format Phone Number to 9 digits

I have a column with phone numbers in varchar, currently looks something like this. Because there is no consistent format, I don't think substring works.
(956) 444-3399
964-293-4321
(929)293-1234
(919)2991234
How do I remove all brackets, spaces and dashes and have the query return just the digits, in Snowflake? The desired output:
9564443399
9642934321
9292931234
9192991234
You can use regexp_replace() function to achieve this:
REGEXP_REPLACE(yourcolumn, '[^0-9]','')
That will strip out any non-numeric character.
You could use regexp_replace to remove all of the special characters
something like this
select regexp_replace('(956) 444-3399', '[\(\) -]', '')
An alternative using translate . Documentation
select translate('(956) 444-3399', '() -', '')

Redshift SQL REGEXP_REPLACE function

I have a value which is duplicated from source (can't do anything about that). I have read some examples here https://docs.aws.amazon.com/redshift/latest/dg/REGEXP_REPLACE.html
Example value:
ABC$ABC$
So just trimming anything after the first '€'. I tried this, but I cannot figure out the correct REGEX expression.
REGEXP_REPLACE(value, '€.*\\.$', '')
So just trimming anything after the first '€'.
Why use regex at all? Why not just..
SELECT LEFT(value, CHARINDEX('€', value)-1)
If not all your data has a euro sign, consider WHERE value like '%€%'
Your current regex pattern is including a dot as the final character. Remove it and your approach should work:
SELECT REGEXP_REPLACE(value, '€.*$', '') AS value_out
FROM yourTable;
Or you can take the initial sequence of non-€ characters:
REGEXP_SUBSTR(value, '^[^€]+')

Get substring from string db2

I have 2 strings for exampe:
FO-123-4444-3353-9999-TEXT and
123-4444-3353-88888-something
How can i get substring without TEXT,something on the end and if there is FO also without FO. FO will be always there or won't , but TEXT can have any other word instead
Final result shoul be:
123-4444-3353-88888 and
123-4444-3353-9999
If you want to replace FO- in the beginning and -TEXT in the end, use regexp_replace. It can be done in single regexp using OR (|)
select regexp_replace('FO-123-4444-3353-9999-TEXT','^FO-|-TEXT$','') from SYSIBM.SYSDUMMY1;
Result:
123-4444-3353-9999
This answers the original version of the question.
Assuming that "TEXT" and "FO" do not appear anywhere else in the string (as in your examples), you can use REPLACE():
select replace(replace(col, '-TEXT', ''), 'FO-', '')
For the revised question, you can use regexp_replace():
select regexp_replace(col, '^FO-|-TEXT[0-9]*$', '')
This assumes that the "FO" and "TEXT" are at the beginning and end of your strings.

How to remove empty spaces in SQL

Can anyone help me to remove empty spaces from the beginning of a string. In a column, there are different number of empty spaces in each entry. How to eliminate them? Thanks a ton in advance
If you wanted to remove the empty spaces from the beginning of a string,Use LTRIM.
SELECT LTRIM(YourColumn)
FROM YourTable
if you wanted to remove all the spaces,use the below script (specific to SQL server).
SELECT LTRIM(RTRIM(REPLACE(YourColumn,' ','')))
FROM YourTable
Use LTRIM or TRIM depending on your database/version.

Remove all characters at the beginning of string up to certain character in Oracle

I have an address field in which I only want to extract only the city and the state. The data is stored as such: (1234 Cherry ST_Sometown_ST). I would like to removed everything up to and including the first underscore. Is there an easy way to do this with REGEXP_REPLACE() or another similar function?
The only think I have found so far is the ability to remove an Nth number.
Try this
SQL Fiddle Demo
select substr(address, instr(address, '_') + 1, length(address)) as "CityState"
from address