I use this regex for extract email:
regexp_replace(xxx, '.*=([A-Za-z0-9._%-]*#[A-Za-z0-9._%-]*\.[A-Za-z]{2,4}).*','\1')
regexp_like(xxx,'=+[A-Za-z0-9._%-]+#[A-Za-z0-9._%-]+\.[A-Za-z]{2,4}')
I can extract string like this:
select regexp_replace('/AAA-SSS-CCC?User=testmail#mail.com?Id=12323424','.*=([A-Za-z0-9._%-]*#[A-Za-z0-9._%-]*\.[A-Za-z]{2,4}).*','\1')
Output: testmail#mail.com
But I can't extract string like this:
select regexp_replace('/AAA/SSS/CCC/testmail#mail.com?Id=12323424','.*=([A-Za-z0-9._%-]*#[A-Za-z0-9._%-]*\.[A-Za-z]{2,4}).*','\1')
Output: /AAA/SSS/CCC/testmail#mail.com?Id=12323424
How can I do that?
Thanks.
Try This. I have modified the pattern to be matched before # appears. It matches one or more occurrence of any character other than #, which matches / .
SELECT REGEXP_REPLACE (
'/AAA/SSS/CCC/testmail#mail.com?Id=12323424',
'^([^#]+)#[A-Za-z0-9._%-]*\.[A-Za-z]{2,4}.*',
'\1')
FROM DUAL;
Related
I have a string that contains ID numbers, something like this: „1;3;5;6;7;“
I want to select all rows in an SQLite table that have an ID which is contained in that string.
One select statement that gives me the rows 1,3,5,6 and 7.
Any idea how to do this?
You can do it with LIKE operator:
select * from tablename
where ';' || '1;3;5;6;7' || ';' like '%;' || id || ';%'
You can use the SQLite instr core function
SELECT * FROM your_table WHERE instr(';'||'1;3;5;6;7;',';'||id||';');
preceding the list with ; and wrapping the id in ;'s ensures that only the specific values are extracted (e.g. so that 1 doesn't get 11 111 etc)
I need to get all the matches of a regular expression in a text field in a MariaDB table. As far as I know REGEXP_SUBSTR is the way to go to get the value of the match of a regular expression in a text field, but it always returns after the first match and I would like to get all matches.
Is there any way to do this in MariaDB?
An example of the content of the text field would be:
#Generation {
// 1
True =>
`CP?:24658` <= `CPV?:24658=57186`;
//`CP?23432:24658` <= `CPV?:24658=57186`
// 2
`CP?:24658` <> `CPV?:24658=57178` =>
`CP?:24656` <> `CPV?:24656=57169`;
And the select expression that I'm using right now is:
select REGEXP_SUBSTR(textfield,'CP\\?(?:\\d*:)*24658') as my_match
from table
where id = 1243;
Which at the moment returns just the first match:
CP?:24658
And I would like it to return all matches:
CP?:24658
CP?23432:24658
CP?:24658
Use just REGEXP to find the interesting rows. Put those into a temp table
Repeatedly process the temp table -- but remove the SUBSTR as you use it.
What will you be doing with each substr? Maybe that will help us devise a better approach.
I'm using this code:
SELECT *
FROM TableName
WHERE (ColumnName >= '' AND ColumnName < '豈')
OR (ColumnName >= '' AND ColumnName < '')
OR (ColumnName >= '' AND ColumnName < '');
from this answer - but it only returns entries that begin with anything in those ranges.
I need to be able to find entries that don't begin with characters in those ranges but contain characters that exist in the above ranges.
I have tried changing
'' AND ColumnName < '豈'
to
'%""%' AND CHS < '%"豈"%'
hoping that would work - but it evidently doesn't work like that.
How can I get this to work?
For single characters, you could use LIKE, but character ranges require GLOB:
SELECT ...
FROM MyTable
WHERE ColumnName GLOB '*[-豈]*'
OR ColumnName GLOB '*[-]*'
OR ColumnName GLOB '*[-]*';
The only way to do this with standard SQL would be to include an OR clause for each and every character within your ranges:
SELECT * FROM Table WHERE
ColName LIKE '%X%' OR
ColName LIKE '%Y%' OR
ColName LIKE '%Z%' . . .
which is tedious and probably not practical depending on how many characters are in your ranges.
Two other options you can look at are regular expressions, represented in SQLite with the REGEXP operator:
SELECT * FROM Table WHERE ColName REGEXP 'regular_expression'
or else full text search, documented here: http://www.sqlite.org/fts3.html.
I have a string with value as '12A,12B,12C,13,14'.
I want to check whether '2A' is available in the above string.
while trying my value '2A' checks in 12A and returns as matched.
Please give me a solution for this.
You can do something like this:
select * from table where ',' || col || ',' like '%,2A,%';
Commas are concatenated to the column to cover the cases where the element is present at the start or end of the string.
for example my "select" query returns rows:
"asd/1"
"asd/2"
but for me rows "asd/1", "asd/2" represents the same value. Is any way to truncate strings to such result: (i want to truncate everything after '/' inclusive)
"asd"
??
Something like this should work
select distinct substr(column_name, 1, instr(column_name, '/') - 1) from table_name
This get back column_name up to the first '/' in the string (but not including the slash because of the -1) and then only give back the unique results (because of the distinct keyword)