Regex Replace First Number from Phone number if it is a 1 - replace

I've got a list of phone numbers in bigquery.
Some have the number 1 in front and some do not. I would like to remove the 1s using regex replace:
The data looks as follows:
16047779887
4037778776
And I would like to return:
6047779887
4037778776
Any help is appreciated!

Select regex_replace(column_name, "1*", "")
from table
The * represents the rest of the string.
If the first letter is 1, remove it. (replace it with an empty string)

Related

Regex for values that are in between spaces

I am new to regex and having difficulty obtaining values that are caught in between spaces.
I am trying to get the values "field 1" "abc/def try" from the sameple data below just using regex
Currently im using (^.{18}\s+) to skip the first 18 characters, but am at at loss of how to do grab values with spaces between.
A1234567890 field 1 abc/def try
02021051812 12 test test 12 pass
3333G132021 no test test cancel
any help/pointers will be appreciated.
If this text has fixed-width columns, you can match and trim the column values knowing the amount of chars between start of string and the column text.
For example, this regex will work for the text you posted:
^(.*?)\s*(?<=.{19})(.*?)\s*(?<=^.{34})(.*?)\s*(?<=^.{46})
See the regex demo.
So, Column 2 starts at Position 19, Column 3 starts at Position 34 and Column 4 (end of string here) is at Position 46.
However, this regex is not that efficient, and it would be really great if the data format is fixed on the provider's side.
Given the not knowing if the data is always the same length I created the following, which will provide you with a group per column you might want to use:
^((\s{0,1}\S{1,})*)(\s{2,})((\s{0,1}\S{1,})*)(\s{2,})((\s{0,1}\S{1,})*)
Regex demo

Alteryx - Split a string with an uncertain length into 5 characters per column

I am trying to split a string (the string length is uncertain; it could be 500 characters or 1500 characters) into multiple columns, and each column should only contain 5 characters.
For example,
If column A contains the string:
AAGANAB5ARAB7AAAB9AAAC--CAC--1ACMRD
Then, I need Column B to Column H to be:
AAGAN,
AB5AR,
AB7AA,
AB9AA,
AC--C,
AC--1,
ACMRD
Also, the string contains “-“, but it is NOT delimiter. It should also be counted as a part of 5 char strings.
I know RegEx is probably the function I should use, and just by putting "(.....)" in the Regular Expression, Alteryx can extract the first 5 characters. But I don't know how to ask Alteryx to automatically split the entire string (length varies each row) to columns of 5 chars.
In Alteryx, use their RegEx tool (instead of the Formula tool with one of their REGEX expressions). In the config panel of the RegEx tool, and simply enter ..... as the RegEx, and the key is to select "Split to Rows"... this will give you rows with a new field that is the result of the applied RegEx.

Reg exp search in notes/comments/description data in PostgreSQL 10.7

I have a scenario which I am not able to do in 10.7 version. Basically, I have a data column in which I need to find the Reg Exp pattern inside the data which is in the form of notes/comments/description.
For example, Data in the column : The SSN number is 760-56-6289
In the above data 760-56-6289 is the actual SSN number which I need to find across all schemas/tables/columns for the defined reg exp pattern. And, we can have a pre or post text for actual SSN value.
Could you please let me know how to achieve this PostgreSQL 10.7?
Please let me know if you need more information for the same.
demo:db<>fiddle
SELECT
(regexp_matches(mycolumn, '^.*([\d]{3}-[\d]{2}-[\d]{4}).*$'))[1]
FROM mytable
The RegEx means:
Start of text: ^
arbitrary number of characters: .*
group of your number: (...)
3 digit characters: [\d]{3}
- character
2 digits: [\d]{2}
- character
4 digits: [\d]{4}
arbitrary number of characters: .*
end of text: $
regexp_matches() gives out all found groups as an array. So, there is only one group, the array contains only one value. This is your number which can be get with the index [1]

Go through set of numbers and getting all possible matches

I'm trying to go through a set of numbers like "123456789123456" and I want to be able to find every single combination of numbers I can, that is 8 long, and it's starting point increasing by 1 for every match.
I'll use [] as where the expression starts, and then counts from.
Example:
First match: [1]23456789123456 would find: 12345678
Second match: 1[2]3456789123456 would find: 23456789
Third match: 12[3]456789123456 would find: 34567891
and so on...
I'm fairly new to Regex so I don't have a ton of experience in it.
You don't really need regex for this. Just a simple loop should do:
Dim input As String = "123456789123456"
For i As Integer = 0 To input.Length - 8
Console.WriteLine(input.Substring(i, 8))
Next
12345678
23456789
34567891
45678912
56789123
67891234
78912345
89123456

extract number from string in Oracle

I am trying to extract a specific text from an Outlook subject line. This is required to calculate turn around time for each order entered in SAP. I have a subject line as below
SO# 3032641559 FW: Attached new PO 4500958640- 13563 TYCO LJ
My final output should be like this: 3032641559
I have been able to do this in MS excel with the formulas like this
=IFERROR(INT(MID([#[Normalized_Subject]],SEARCH(30,[#[Normalized_Subject]]),10)),"Not Found")
in the above formula [#[Normalized_Subject]] is the name of column in which the SO number exists. I have asked to do this in oracle but I am very new to this. Your help on this would be greatly appreciated.
Note: in the above subject line the number 30 is common in every subject line.
The last parameter of REGEXP_SUBSTR() indicates the sub-expression you want to pick. In this case you can't just match 30 then some more numbers as the second set of digits might have a 30. So, it's safer to match the following, where x are more digits.
SO# 30xxxxxx
As a regular expression this becomes:
SO#\s30\d+
where \s indicates a space \d indicates a numeric character and the + that you want to match as many as there are. But, we can use the sub-expression substringing available; in order to do that you need to have sub-expressions; i.e. create groups where you want to split the string:
(SO#\s)(30\d+)
Put this in the function call and you have it:
regexp_substr(str, '(SO#\s)(30\d+)', 1, 1, 'i', 2)
SQL Fiddle