REGEXP_SUBSTR question
Good day to you all:
I have a column in a table that contains the names of files as such:
EXAMPLE1.05232014.BUSINESS.PDF
EXAMPLE2.05182014.SUPPORT.DOCX
EXAMPLE3.02252014.OPERATIONS.GIF
How to use the REGEXP_SUBSTR function to extract the file extension? My desired to above data output would be:
. DOCX
. GIF
Please, if there is a way easier to extract file extension share, as I have mucho problemos with REGEXP_SUBSTR command.
SQL DEVELOPER VERSION Version 3.2.20.09 - Oracle 10 g environment
Thank you very much for your help!
I appreciate the expertise here...
Hello
With the help of regular expressions:
REGEXP_SUBSTR (file_name
, '\. [^.] *$'
)
Without them (probably faster):
SUBSTR (file_name
, INSTR (filename, ".", - 1).
)
Want to sure if the filename does not contain any '.'s at all? The above expression REGEXP_SUBSTR returns NULL and the expression of SUBSTR returns the file_name, but either can be replaced.
Tags: Database
Similar Questions
-
Questioning REGEXP_SUBSTR, regular expressions
With the expression below, I expect to come back the first 4 words and do not understand why it is not doing.
db > select regexp_substr('This is a sample text string', '([[:alpha:]]+){3,4}') from dual; REGE ---- This
This works as expected.
db > select regexp_substr('This is a sample text string', '([[:alpha:]]+ ){3,4}') from dual; REGEXP_SUBSTR('TH ----------------- This is a sample
Hello
Solomon Yakobson says:
Frank Kulash wrote:
If you are looking for 3 or 4 instances of 1 or more letters, without anything in addition to the letters between them. Any group of 3 or more consecutive letters matches. For example,.
- "Th" as the 1st appearance of 1 or more letters,
- 'i' as the 2nd appearance of 1 or more letters, and
- of ' as the 3rd appearance of 1 or more letters
is a substring that matches the pattern you described.
In fact T is the 1st appearance of 1 or several letters, h is the second, I ranked third and s are defined. Otherwise:
SQL > select regexp_substr ('the following is an example of text string', ' ([[: alpha:]] +) {3,4}') of the double
2.REG
---
TheSQL >
returns no rows.
Not that it is important for the OP's question, but I think the way I presented it is more precise.
How can tell us if 'This' match of the 4 occurrences (all 1 character) or 3 occurrences (1 with 2 characters and 2 with 1 character each)?
In more general terms, when we say something like
(expr +) {x, y}
is '+' more greedy than "{x, y}.
It seems to me that '+' is dishonest in this case. Consider this query:
WITH sample_data AS
(
SELECT "This is an example of text string" dual UNION ALL STR
SELECT 'the following is an example of text string' FROM dual UNION ALL
SELECT 'Fubar' double UNION ALL
SELECT 'chat' FROM dual
)
SELECT str
REGEXP_REPLACE (str
, ' ([[: alpha:]] {1,2})([[:alpha:]]+) ([[: alpha:]] +)([[:alpha:]]+)?'
, "\1=1;\2=2;\3=3;\4=4".
) And matches
OF sample_data
;
which produces this output:
STR MATCHES
------------------------------------- ------------------------------
This is an example of text string Th = 1; i = 2; s = 3; = 4 is a samp = 1; l =
2; e = 3; 4 = = you 1; x = 2; t = 3; = 4 = stri
1; n = 2; g = 3; = 4
The following is an example of text string T = 1; h = 2; e = 3; = 4 followi = 1; n = 2; g
= 3 ; = 4 is a samp = 1; l = 2; e = 3; = 4 t
e = 1; x = 2; t = 3; = stri 4 = 1; n = 2; g = 3;
= 4
Fubar Fub = 1; a = 2; r = 3; = 4
cat c=1;a=2;t=3;=4
In this case, '+' appears to be labels as "{3.4}.
I don't have not seen this documented anywhere, but it seems it's because + gets to go first in the model. In other words, there is nothing to inherently rapacity on ' + '. If we change the first '+' above "{1,9}", like this
WITH sample_data AS
(
SELECT "This is an example of text string" dual UNION ALL STR
SELECT 'the following is an example of text string' FROM dual UNION ALL
SELECT 'Fubar' double UNION ALL
SELECT 'chat' FROM dual
)
SELECT str
REGEXP_REPLACE (str
, ' ([[: alpha:]]{1,9}) ([[: alpha:]] +) ([[: alpha:]] +)([[:alpha:]]+)?'
, "\1=1;\2=2;\3=3;\4=4".
) And matches
OF sample_data
;
the result remains the same.
Of course, is using the first query I posted above
(expr) (expr) (expr) (expr)?
It is possible that
(expr) {3,4}
which is what OP posted, is handled differently.
-
Question about REGEXP_SUBSTR
Dear experts.
I would like to cut the chain TI - C, EN - C of the PBDA. JP - C, JPTYOOF-R * DPPD | TI - C, EN - C.
SELECT REGEXP_SUBSTR (' PBDA |) JP - C, JPTYOOF-R * DPPD | TI - C, EN-it, ' [^ |] + |', 1, 3) twice;
The statement above works well, but don't you think it would be wise to let | with exit-outside [].
When I use the Sub statement I'm NULL.
SELECT REGEXP_SUBSTR (' PBDA |) JP - C, JPTYOOF-R * DPPD | TI - C, EN-it, ' [^ |] + \|',1,3) twice;
Could you please suggest me some alternatives.
Thank you
Rajat
This way:
with the data as
(
Select ' PBDA | JP - C, JPTYOOF-R * DPPD | TI - C, C - EN "double pass".
)
Select col, regexp_substr (col, ' [^ |] +' 1, 3)
data;
However, I would suggest using the SUBSTR function because the evaluation of the regular Expression tends to be expensive if you are dealing with huge data.
-
question simple regexp_substr
Hi all
version 10g
I want the string substr and get the point of atfer (.) string
result'abcd.xyz1'
XYZ1
Thank you
Published by: new learning on 10 Sep, 2010 08:12Hello
Here's one way:
REGEXP_SUBSTR ( str , '[^.]+$' )
The. is not a wild-card in this regard.
What happens if there are plusieurs.s in str?
The expression above all will return (if any) after the last of them.Published by: Frank Kulash, Sep 10, 2010 11:20
You specifically asked about REGEXP_SUBSTR.
Regular expressions tend to be slower than the old ways, if both involve on the amout of code.
You can get the same results faster using SUBSTR, as Iamaby suggested.
To get the text (if any) after the last point:SUBSTR ( str , 1 + INSTR (str, '.', -1) )
-
Question on connect by level 2 records
My query begins with the records of two pairs and continues with the rank and adds two records to pair again.
However, the unwanted extra each level (mbc 11, 12 wtc...) in the result.
would you help me.
My request;
SELECT CUT (SUBSTR ("abc 11 12 11 22 33 kbc vbc wtc mbc mbc 17 45', INSTR kbs (" abc 11 12 11 22 33 17 mbc kbc vbc wtc mbc kbs 45 ', ' ', 1, level) + 1, "))
INSTR ("abc 11 12 11 22 33 17 mbc kbc vbc wtc mbc kbs 45 ', ' ', 2, level + 1)-INSTR (" abc 11 12 11 22 33 17 mbc kbc vbc wtc mbc kbs 45 ', ' ', 1, level)-1)) AS PAIR
OF THE DOUBLE
CONNECT BY level < = LENGTH(' abc 11 mbc 12 wtc 11 vbc 22 kbc 33 mbc 17 kbs 45 ') LENGTH (REPLACE ('abc 11 12 11 22 33 17 mbc kbc vbc wtc mbc kbs 45', ' ', "))-1
Outcome;
ABC 11 MBC 12 WTC 11 Vbc 22 KBC 33 MBC 17 KBS 45 Problem result;
ABC 11 11 mbc MBC 12 WTC 12 WTC 11 11 vbc Vbc 22 22 kbc KBC 33 MBC 33 MBC 17 17 kbs KBS 45 Hello
Jimmie_M wrote:
I thank very you much for your time. Thank you!!!
is it possible to keep my request to get the result without regexp_substr.
If I run regexp_substr in the table, the slow performance.
Thank you
You were on the right track with your first message. The problem with this request was that you were each pair of words:
- Word 1 and 2,
- Word 2 and 3,
- Word 3 and 4,
- Word 4 and 5,
and so on. You don't want that every other pair:
- Word 1 and 2,
- Word 3 and 4,
and so on.
Here's a way to do it:
WITH the data AS
(
SELECT ' abc 11 12 11 22 33 kbc vbc wtc mbc mbc 17 45' AS str kbs
OF the double
)
got_space_pos AS
(
SELECT 1 * LEVEL AS n
, INSTR (str, ' ', 1, (2 * LEVEL)-1) + 1 AS start_pos
, INSTR (str, ' ', 1, (2 * LEVEL) + 1) AS end_pos
FROM the data
CONNECT BY LEVEL<= (="" length="">=>
-LENGTH (REPLACE (str, ' '))
) / 2
)
SUBSTR (str, start_pos, end_pos - start_pos) SELECT as a PAIR
OF got_space_pos
JOIN CROSS data
ORDER BY start_pos
;
Output:
PAIR
-------------
ABC 11
MBC 12
WTC 11
Vbc 22
KBC 33
MBC 17
KBS 45
Are you regular expressions of course are initially slow Paulzip query? That's maybe something about your data you have not shown or explained. As said by ground, you must always follow the Forum FAQ:
Re: 2. How can I ask a question in the forums?
so that people who want to help you can recreate the problem and test their ideas.
In addition, the sample data (CREATE TABLE and INSERT statements), be sure to upgrade your version of Oracle. A recursive (available in Oracle 11.2 and upwards) WITH clause might help in this problem. or maybe CROSS APPLY (Oracle 12.1) would be useful.
Simplify the prblem as much as possible; for example, you generally need not show all columns in your actual tables, only those involved in the problem. But make sure that you validate the example data illustrate the real problem.
-
regexp_substr: retrieve a block of text between delimiters
Hello
regexp_substr is very powerful, but not so easy to understand. I'll try to do my best, but I need your help.
My question is this: I have a multiline text, stored in a database field. The text is structured as a "windows.ini" file: there are sections in square brackets and the lines of text in the section.
I want to retrieve all of the text in a given section, and I think it's possible using regexp_substr.
Here is the text of the field (in bold the part I want back):
---
[ARTICLE 1]
AAA = 123
BBB = 456
CCC = 789
[ARTICLE 2]
DDD = 987
EEE = 654
---
In other words, is there a way to retrieve the text between [ARTICLE 1] and [ARTICLE 2]?
Thank you in advance.
Concerning
Select
regexp_substr (txt, ' [de] [^] +', 1, level * 2) s
t
connect by level<= regexp_count(txt,="">=>
-
The following regular expression separates simple values separated by commas (SELECT regexp_substr (: pCsv,'[^,] +', 1, level) FROM DUAL CONNECT BY regexp_substr (: pCsv, ' [^,] +', 1, level) IS NOT NULL); Exampple: 300100033146068, 300100033146071, 300100033146079 returns 300100033146068 300100033146071 300100033146079
This works very well if we use the regex with SQL IN operator select * from mytable where t.mycolumn IN (SELECT regexp_substr (: pCsv,'[^,] +', 1, level) FROM DUAL CONNECT BY regexp_substr (: pCsv, ' [^,] +', 1, level) IS NOT NULL);
But this query does not work if the comma-separated value is a single literal string 'one', 'two', 'three '.
Thanks for your reply. my request was mainly on regexp_substr. Need to request was simple: any table with a column of varchar type can be used. Next time I'll give you an example.
All ways working answer for my question is is SELECT regexp_substr (: pCsv,'[^, "] +', 1, level) FROM DUAL CONNECT BY regexp_substr (: pCsv, ' [^,"] +', 1, level) IS NOT NULL
-
REGEXP_SUBSTR, CONNECT BY slowing down with value
I have the following sql code
SELECT distinct q.broker_ID, q.user_ID, q.MGC_BREACH_ALERT, REGEXP_SUBSTR (nvl(q.CGC_ALERT_THRESHOLDS,0), "[^ |]") +', 1, LEVEL) value
Of
(select u.broker_ID, t.user_ID, t.CGC_ALERT_THRESHOLDS, ATSD_USE_TRADERS t.MGC_BREACH_ALERT t, ATS_USERS u where u.user_ID = t.user_ID and t.sponsored_user = 1) q
CONNECT TO (REGEXP_SUBSTR (nvl(q.CGC_ALERT_THRESHOLDS,0), "[^ |]")) +', 1, LEVEL) IS NOT NULL)
order by 1
When all the values in the table has CGC_ALERT_THRESHOLDS as two pipes separate values (for example 34 | 44) the query runs in less than 1 second.
When the CGC_ALERT_THRESHOLDS are the three values of separate pipes (for example 34: 44 | 54) then the request takes longer than 30 seconds to complete.
The table has only 150 lines.
Can you please explain where I have gone wrong / or any other suggestions for improvements to this request?
Hello
Whenever you have a question, please post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and the accurate results you want from this data, so that people who want to help you can recreate the problem and test their ideas.
Explain, using specific examples, how you get these results from these data.
Always say what version of Oracle you are using (for example, 11.2.0.2.0).
See the FAQ forum: Re: 2. How can I ask a question on the forums?
Jones wrote:
I have the following sql code
SELECT distinct q.broker_ID, q.user_ID, q.MGC_BREACH_ALERT, REGEXP_SUBSTR (nvl(q.CGC_ALERT_THRESHOLDS,0), "[^ |]") +', 1, LEVEL) value
Of
(select u.broker_ID, t.user_ID, t.CGC_ALERT_THRESHOLDS, ATSD_USE_TRADERS t.MGC_BREACH_ALERT t, ATS_USERS u where u.user_ID = t.user_ID and t.sponsored_user = 1) q
CONNECT TO (REGEXP_SUBSTR (nvl(q.CGC_ALERT_THRESHOLDS,0), "[^ |]")) +', 1, LEVEL) IS NOT NULL)
order by 1
When all the values in the table CGC_ALERT_THRESHOLDS as two pipes separate values (for example 34: 44) the query runs in less than 1 second.
When the CGC_ALERT_THRESHOLDS are three pipes separated values (for example 34: 44 | 54) then the query takes more than 30 seconds to complete.
The table has only 150 lines.
Can you please explain where I have gone wrong / or any other suggestions for improvements to this request?
Whenever you are tempted to use SELECT DISTINCT, think very carefully about why you need it. It is often a way to hide an error in the query.
In this case, the error is using CONNECT BY on a multiple row table, without conditions PRIOR involving. If you have 150 rows in the table, this means that you will
150 lines level = 1,
150 * 150 = 22500 ranks LEVEL = 2,
150 * 150 * 150 = 3375000 rows = 3 LEVEL.
...
Soon, which will be a large number of lines.
You must change the CONNECT BY clause into something like:
CONNECT BY REGEXP_SUBSTR (NVL (q.cgc_alert_thresholds, '0'))
, '[^|] +'
1
LEVEL
) IS NOT NULL
AND PRIOR SYS_GUID () IS NOT NULL
AND PREREQUISITE uk = uk - uk is a unique key
I can't be sure without your sample data.
-
Simple question: how to divide the string into multiple lines concatenated?
Hi people,
Maybe it's an easy question.
How to split a string that is concatenated into multiple lines by using the SQL query?
ENTRY:
Delimiter = ', '.select 'AAA,BBB,CC,DDDD' as data from dual
Expected results:
I'm looking for something nice to feature "an opposite to «sys_connect_by_path»»data ------------ AAA BBB CCC DDDD
Thank you
Tomaswith t as (select 'aaaa,,bbbb,cccc,dddd,eeee,ffff' as txt from dual) -- end of sample data select REGEXP_SUBSTR (txt, '[^,]+', 1, level) from t connect by level <= length(regexp_replace(txt,'[^,]*'))+1 REGEXP_SUBSTR(TXT,'[^,]+',1,LE ------------------------------ aaaa bbbb cccc dddd eeee ffff
-
iOS 10 people record problem/question
Hello
I have a couple of "faces" in the issue of people who are coming in white, but acknowledged same 'face' of many times. Is anyway to update it for photo comes actually? At a few faces, I don't know that facial recognition found since it is coming from white.
Hi JohnP007,
Congratulations on your iPhone 7 more running iOS 10! I understand that some of your faces in the album of people pull up as a draft and you want to refresh. You can try to use the steps below to fix the faces on the thumbnails in albums.
Difficulty faces and names mixed-up
If you notice that there is a photo of someone in a collection that is poorly identified, you can remove it.
- Tap the person you want to remove in the album of people > select.
- Type Show done face to emphasize his face in every photo.
- Press on each photo that is not the person.
- Type > not this person.
Hide people
You can hide the people or groups that you don't want in your album of people.
- Open the album people and press Select.
- Touch the people you don't want to see.
- Click Hide.
If you want to see the people that you have hidden, press on show hidden people.
People in the Photos on your iPhone, iPad or iPod touch
This should be corrected without delay faces. Please use the Apple Support communities to post your question. Good day.
-
Questions - and answers forgotten
How to get my 'secret' answers to the questions that I have noted the way back when?
If you forgot the answers to your questions of security of Apple ID - Apple Support
-
I can't reset the security questions. We received notice as below:
Hello world
I can't reset the security questions. We received notice as below:
"Cannot reset Security Questions."
We have insufficient information to reset your security questions. "
Please help me as soon as possible! Thank you very much.
Hello
You will need to contact the Apple Support.
The information is available here:
Contact Apple for assistance with the security of the Apple ID - Apple Support accounts
(I'm afraid that no one here can solve the problem for you - this is a user-based community).
-
Question of cloning for SSD upgrade on 12 Macbook Pro
Previously, I did an upgrade to SSD on my Macbook Air to 2012 according to the instructions of JetDrive transcend. Basically connection via USB 3 and using Mac OS X to clear (and format) disc utilities new SSD, then restore again SSD and then remove the original 128 GB SSD and insert the new 480 GB SSD. For about a month and so far without problem.
Now I'm trying to 2012 Macbook upgrade my Pro partner (on 10.11.6). I got a Crucial SSD MX300 to replace his HARD drive. Crucial comes with (or recommend) Acronis software. And a lot of the messages of the forum recommend Carbon Copy Clone.
My question is if I can use the same method for the cloning of the HD as my Macbook Air (just restore disk of Mac OS X utilities)? This time, I'm upgrading HARD drive and I don't know if something is different. At the same time, if I got lucky the first time, I don't not ruin Macbook Pro my spouse this time.
Thank you.
Yes, you can use disk utility to clone your MBP wives, but unlike CCC, it will not clone the recovery and Partition.
-
Question about resolution movie downloads
If I buy a movie at a certain resolution (780p for example), but I want more later re - download at a higher or lower resolution (SD or 1080 p), can I do so and how?
Same question perhaps for music. Some of my songs have been bought before the latest Apple codecs.
Any help is appreciated!
THX!
Once you have made a purchase on the iTunes store, you will see your purchased items in the menu under accounts bar > bought. You can simply select the item purchased and re-upload.
With regard to the resolution of the film for films that are offered, and you select the resolution, you can download it again and select a different resolution. For movies that are available as separate download to SD, 780, or 1080 points, you would be limited to the original resolution you selected.
-
Why I can't ask questions.
I just have a question. I said that I can't ask questions.
Do exactly what you did to make this post, but your question in there instead.
Maybe you are looking for
-
Am I the only one to have a problem with the zoom is constantly disabling feature?
Running iOS on a 6Plus 9.3.3, I continue to turn on zoom and nearly every day he himself turns OFF. Am I the only one experiencing this bug?
-
Compaq s 6830: change the CMOS battery in a compaq 6830 s
I get up a message at startup my CMOS battery charge level is low, so I want to change it. The computer works well except that. I have no idea where on the map, it is or how to access it. 8.1 Windows installed without any problems.
-
parental control works do not (time curfew does not)
I have windows 8 on my laptop Acer Aspire, I setup as an administrator and my son is set up as a user. I tried to implement curfews in time for my son using the family safety settings. I went to the Microsoft website for Windows 8 and follow-up al
-
' ' MUST BE ANSWERED ON ' HOW TO PUT THE COMPUTER IN SAFE MODE "PLEASE
I HAVE A COMPUTER THAT I NEED TO PUT IN 'SAFE MODE' QUESTION WHAT SHOULD I DO TO PUT IN SAFE MODE?I TRY WITH MY KEY "F8", BUT THAT DOES NOT HELP.IS IT ANOTHER WAY THAT THIS IS POSSIBLE?PLEASE SEND ME E-MAIL ON THIS ISSUE PLEASE... MY COMPUTER IS DOWN
-
I have a gateway MT6460, Windows Vista 32-bit model. I got this update for my sound card on the site of the bridge, it has downloaded to my desktop and double clicked on it when it was all the download and it came with this error message. It is not a