Help REGEXP_REPLACE
Hi all
I tried to replace the characters all before X.
For example, in this case, the X is replaced by 0
Select REGEXP_REPLACE (12X99999', '[Aa - Zz]','0 ') of the double
120to 99999
I want to replace 12 X 0, so I want to replace 12X99999 and see 00099999.
Can someone help me?
Thank you.
Select RPAD ('0', REGEXP_INSTR(s,'[A-Za-z]'),'0 '). REGEXP_REPLACE(s,'.+[A-Za-z]') of
(SELECT "12 X 99999" s FROM DUAL ")
Tags: Database
Similar Questions
-
helps the regexp_replace - converting numbers to strings
I try to use regexp_replace replace all occurrences of the type (number) (in brackets with a number inside) with the expression ('number') (add "before and after the number, and by here - to transform the number to varchar).
I can't find a way to do it properly.
It would be great if you guys could help out me here.
Example-
Before change: abcde (737) (6) s (v) sbsgs37
After change: abcde('737') s sbsgs37('6') (v)
Thank you
Ilya Golosovsky.
("Select REGEXP_REPLACE (' abcde (737) (6) s (v) sbsgs37 ', '\((\d+)\) ', q '[('\1 ')]')
of qry
Result:
ABCDE('737') s sbsgs37('6') (v)
q "[.. '] is called a string q, it allows us to embed single quotes in string literals without having to get away from them."
\((\d+)\)
- ------(corresponds to the character (literally
- 1 capturing group (\d+)
- \d+ matches a digit [0-9]
- Quantifier: + between one and unlimited times, as many times as possible, giving necessary [greedy]
- \d+ matches a digit [0-9]
- \) corresponds to the character) literally
('\1')
- 1 capturing group ("\1")
- literally "corresponds to the character.
- \1 matches the text even more recently matched by the capturing group 1
- literally "corresponds to the character.
-
Hi all, need help with replacing or Regexp_Replace
Hi all
I have a string with me, i.e. '9 03000200090 R R 9 R 9 9 1 9 2 R R 001535447 R 1 R Y R Y 4 1 100002589 1 9 9 9 9 9 9 00002589'
Now, I would like to remove R-9 characters of my channel, look to the characters below marked "BOLD" - these are those, I want to delete.
"9 03000200090 R R R 9 9 9 1 9 2 R 001535447 R 1 R Y R Y 4 1 100002589 1 9 9 9 9 9 9 00002589' R '.
Want my output end: ' 03000200090 1 2 001535447 1 Y Y 4 1 100002589 100002589'.
Can someone help me please?
Thank you
Amit
Hi, amit,
Here's one way:
SELECT REPLACE (REGEXP_REPLACE (REPLACE (str)
, ' '
, ' '
)
, '(^| ) [R9] ( |$)'
)
, ' '
, ' '
)
FROM table_x
;
With a little more coding, your could do it without regular expressions.
-
Helps the REGEXP_REPLACE
Hello Experts
I'm unable to analysis at the address below. Please see the part of the desired effect.
Please help solve this problem. I have tried the REGEXP_REPLACE but could not obtain the success.
Is the version of Oracle, I'm working on that
Oracle Database 11 g Enterprise Edition Release 11.1.0.7.0 - 64 bit Production
With partitioning, OLAP, Data Mining and Real Application Testing options
Thank you
RB
with table1 as
* (by selecting '1805SOUTHETHELAVE' addr1 throughout Union double *)
Select '1165MCALLISTERRD' addr1 Union double all the
Select '2161COMMERCCDR APT206' addr1 Union double all the
Select '1048HARPERLEEDR' addr1 Union double all the
Select '20021NWCR4290' double addr1
*)*
looking for a SOLUTION AS
* 1805 SOUTHETHEL AVE *.
* 1165 MCALLISTER RD *.
* 2161 COMMERCC DR. *
* DR. HARPERLEE 1048 *.
* 20021 NWCR 4290 *.Hello
Here's one way:
SELECT addr1 , REGEXP_REPLACE ( addr1 , '(\d+)([[:alpha:]]+)(AVE|DR|RD|\d+).*' , '\1 \2 \3' ) AS new_addr1 FROM table1 ;
Output:
ADDR1 NEW_ADDR1 --------------------- ---------------------------------------- 1805SOUTHETHELAVE 1805 SOUTHETHEL AVE 1165MCALLISTERRD 1165 MCALLISTER RD 2161COMMERCCDR APT206 2161 COMMERCC DR 1048HARPERLEEDR 1048 HARPERLEE DR 20021NWCR4290 20021 NWCR 4290
He gets good results of the sample data, but he could get good results for the wrong reasons. I have no way of knowing, since I do not know the reasons why you want to get the results that you do. Explain exactly what you're trying to do. Depending on what you want, you might need nested functions.
-
need help to get the value using the REGEXP_REPLACE function.
I am trying to extract the value placed between "< listitems >... < / listitems >" but I am unable to get these value using the REGEXP_REPLACE function.
select REGEXP_REPLACE('<InputParameters></ParamSet><listitems>14545454</listitems></ParamSet></InputParameters>' ,'(<InputParameters>.*<listitems>)(.*)(</listitems>.*<InputParameters>)' ,'\2') from dual;
Can someone please help me achieve this goal.required output: 1454554
Hello
You forgot the / before the last InputParameters. If fix you that, your code will work.
Here is a slightly different way:
SELECT REGEXP_REPLACE ( '
' , '^.*?14545454 (.*?) .*$' , '\1' ) AS listitems FROM dual ;Least to type, the less likely you will have to make typos.
If there are 2 (or more) elements of listitmes, 1 will be returned.From Oracle 11.1, you can also use REGEXP_SUBSTR. I have Oracle 10.2 avaialable now, so I can test the following, but I think you'd say:
SELECT REGEXP_SUBSTR ( '
' , '14545454 (.*?) ' , 1 , 1 , NULL , 1 ) AS listitems FROM dual;When it comes with the text that is or looks to, XML, consider using XML functions.
-
need help to understand REGEXP_REPLACE
Hi all
I'm new to this site so please forgive me for making mistakes. I have a field 'DESCRIPTION of the STUDENT' and they have the following values
2830 ORO - (2011) Rob Miller [6]
2830 ORO - Cathy Ingrid (2011) [7]
2830 ORO - (2011) Sam Sullivan [8]
2650 Robert Lawson
2660 Pat Ortt (2009)
2690 - mark lively
2710 Tim Lacreta
What I want in my desired output is
(2011) Rob Miller [6]
Cathy Ingrid (2011) [7]
(2011) Sam Sullivan [8]
Robert Lawson
Pat Ortt (2009)
Mark lively
Tim Lacreta
Need help please, I know I have to use REGEXP_REPLACE, but I do not understand how I went through the documentation, but has not been of any help.
Thank youHello
Welcome to the forum!
Whenever you have a problem, please post CREATE TABLE and INSERT statements for your sample data. Since this is your first post, I'll do it for you:
CREATE TABLE table_x ( student_description VARCHAR2 (80) ); INSERT INTO table_x (student_description) VALUES ('2830-BGC - (2011) Rob Miller [6]'); INSERT INTO table_x (student_description) VALUES ('2830-BGC - (2011) Cathy Ingid [7]'); INSERT INTO table_x (student_description) VALUES ('2830-BGC - (2011) Sam Sullivan [8]'); INSERT INTO table_x (student_description) VALUES ('2650 - Robert Lawson'); INSERT INTO table_x (student_description) VALUES ('2660 - Pat Ortt(2009)'); INSERT INTO table_x (student_description) VALUES ('2690 - Mark Lively'); INSERT INTO table_x (student_description) VALUES ('2710 - Tim Lacreta');
Explain how you get the results you want from these data. For example: "I want the student_description part that comes after the substring of characters 3 space-dash-space. Spaces are important, because the first part of student_description, the part I want to delete, can contain a hyphen (for example ' 2830 - ORO - (2011) Rob Miller [6] "). »
I think you want something like this:
SELECT student_description , REGEXP_REPLACE ( student_description , '.* - (.*$)' , '\1' ) AS after_dash FROM table_x ;
«. "*" means "0 or more characters (all).
"-" means exactly what it says: a space, followed by a hyphen, followed by a space. Hyphen has no special meaning outside the brackets.
' $' means the end of the string.It would be more effective to do this particular job without using regular expressions:
SELECT student_description , SUBSTR ( student_description , 3 + INSTR ( student_description , ' - ' ) ) AS after_dash FROM table_x ;
Depending on your needs, you may need to adjust this query if student_description does not always contain ' - '.
Published by: Frank Kulash, December 29, 2011 14:08
-
Help me about features as regexp_substr, regexp_replace
Hello world
Can someone help me understand these functions such as regexp_substr, regexp_replace...
Will be better if Tunis examples with different situations or it may be links
THXits here... in the forum itself.
Introduction to regular expressions...
Vivek L
-
Help needed to add the hyphen in REGEXP_REPLACE
Hi all
I need a help to add the hyphen in my selection criteria so that it does not filter the hyphen.
I use below REGEXP_REPLACE get my result, everything's fine now except the hyphen (-) character is not recognized.
Select REGEXP_REPLACE ('abcd - efgh123 {} $ (), ',' [^ [a - z, A - Z, 0-9, (,), {,}, _, $,., ", [: space:]]] *',") twice;
Can you please help?
Thank youIf you want to keep the hyphen in your string, you can use sth. as
select REGEXP_REPLACE('abcd-efgh123{}$(),', '[^a-zA-Z0-9(){}_$.,''[:space:]-]*','') from dual
Best regards
Maxim
-
need help with regexp_replace
Hello
Can someone help me? I'll try to find a regexp for the following model?
In my paper, here is the model I'd like to remove.
< < snip > >
* [News 16]
* [Sport 17]
* [Leisure 18]
* [19] news
* [20] what you say
* [Family 21]
* [Video 22]
* [23] ads
* [Advertise 24]
* [25] buy/sell
* [26] Click2Find
* [Dating [27]
* [28] cars
* [29 houses]
* [30] jobs
< < snip > >
Thank you
AjayMaybe
regexp_replace(col, '\* \[\d+\][[:alpha:]]+')
-
Hello:
I have a string which will be composed of 1 to 3 rooms. The first separator will be 1 or 2 brands of ' / '. I have a regular expression, which works for most of the data, but not in a particular case, and I don't know why. In the case below where the source is simply the string 'A', all 3 parts are returned as 'A'. I want A PT1 and PT2 and PT3 to be null. Why is this not the case, and how do I change the regular expression to manage this source string?
Thank you.
with base as)
Select ' a / / BCD / / XYZ "as double CBC
Union of all the
Select ' a / / BCD/XYZ "as double CBC
Union of all the
Select ' A / / BCD' as double CBC
Union of all the
Select 'A' as double CBC
)
Select the CBC
regexp_replace (RTrim (SRC), ' ([A - Z] +)(/{1,2}) ([A - Z] *)?) () /+)? ([A-Z] *) ? (',' \1') PT1.
regexp_replace (RTrim (SRC), ' ([A - Z] +)(/{1,2}) (([A-Z]*)?)) (/+)? ([A-Z] *) ? (',' \3') PT2.
regexp_replace (RTrim (SRC), ' ([A - Z] +)(/{1,2}) ([A - Z] *)?) () /+)? ([A-Z] *) ? (',' \5') PT3
Basic
What I get is:
CBC STR PT2 STP A / / BCD / / XYZ A BCD XYZ A / / BCD/XYZ A BCD XYZ A / / BCD A BCD (null) A A A A Hello
You can get what you want more simply using REGEXP_SUBSTR:
SELECT src
, REGEXP_SUBSTR (CBC, ' [^ /] +', 1, 1) AS pt1
, REGEXP_SUBSTR (CBC, ' [^ /] +', 1, 2) AS pt2
, REGEXP_SUBSTR (CBC, ' [^ /] +' 1, 3) AS pt3
BASIC;
-
Help with the Regular Expressions and regexp_replace
Oh great guru Oracle can I can receive assistance
I need to clean the phone numbers that have been entered in the table per_phones of Oracle e-Business. Some of the phone numbers have hyphens, some have spaces and some have tank. I just want to get out all the figures and then re - format the number.
E.g.
914-123-1234... out (914) 123-1234
9141231234... new (914) 123-1234
914 123 1234... (914) 123-1234
MyPhone... just null
(914)-123-1234... (914) 123-1234
I really tried to understand the instructions of regular expressions, but for some reason, I can't understand it.For example:
SQL> with sample_data as ( 2 select '914-123-1234' phone_number from dual union all 3 select '9141231234' from dual union all 4 select '914 123 1234' from dual union all 5 select '(914)-123-1234' from dual 6 ) 7 select regexp_replace( 8 regexp_replace(phone_number, '\D') 9 , '(...)(...)(....)' 10 , '(\1) \2-\3' 11 ) as formatted_num 12 from sample_data 13 ; FORMATTED_NUM -------------------------------------------------------------------------------- (914) 123-1234 (914) 123-1234 (914) 123-1234 (914) 123-1234
-
Regexp_replace? help please
Hi all
I get a VARCHAR2 string, which can contain mostly spaces and enything digital alpha also of special characters.
Right now I use a lot of functions which replaces some things, filling in the spaces.
Basically, I want to use regexp_replace to simply remove all the spaces and characters spacial (commas, slashes rear, ambersands e, t, c) and just take the digital alpha data.
He takes their identity card, then concatenates the two first letters of the name, then the first two letters of firtname firdt two letters of the given name... all the missing characters get stuffed with *.
This is the code I have for the moment
declare rms_id NUMBER := 4767; last_name VARCHAR2(10) := 'fds dgdg'; first_name VARCHAR2(10) := 'tu/ yu rt'; middle_name VARCHAR2(10) := ''; answer VARCHAR2(20); BEGIN SELECT rms_id || rpad(lower(substr(replace(nvl(last_name,'**'),' ',''),1,2)),2,'*') || rpad(lower(substr(replace(nvl(first_name,'**'),' ',''),1,2)),2,'*') || rpad(lower(substr(replace(nvl(middle_name,'**'),' ',''),1,2)),2,'*') INTO answer FROM dual; dbms_output.put_line(answer); END;
So, you want to say something like:
SQL> ed Wrote file afiedt.buf 1 with t as (select 4767 as rms_id, 'fds dgdg' as last_name, 'tu/ yu rt' as first_name, '' as middle_name from dual) 2 -- 3 -- END OF TEST DATA 4 -- 5 select rms_id|| 6 lpad(nvl(substr(regexp_replace(first_name,'[^[:alnum:]]'),1,2),'*'),2,'*')|| 7 lpad(nvl(substr(regexp_replace(middle_name,'[^[:alnum:]]'),1,2),'*'),2,'*')|| 8 lpad(nvl(substr(regexp_replace(last_name,'[^[:alnum:]]'),1,2),'*'),2,'*') 9* from t SQL> / RMS_ID||LP ---------- 4767tu**fd SQL>
-
need help to get the desired outcome of the SQL using REGEXP_REPLACE
Hi all
I have following query column values.
Select (1-4, 8-9, 7, 11-13') twice;
Here, I need to replace the '-' in the sequence number, as shown in the below expected o/p.
Expected results
-------------------------
1,2,3,4,8,9,7,11,12,13
Hello
dbaKrish wrote:
Hi all
I have following query column values.
Select (1-4, 8-9, 7, 11-13') twice;
Here, I need to replace the '-' in the sequence number, as shown in the below expected o/p.
Expected results
-------------------------
1,2,3,4,8,9,7,11,12,13
Its one-way:
WITH got_str AS
(
SELECT ' 1-4, 8-9, 7, 11-13' STR
OF the double
)
got_comma_delimited_parts AS
(
SELECT LEVEL AS part_num
REGEXP_SUBSTR (str,
, '[^,]+'
1
LEVEL
) IN the framework
OF got_str
CONNECT BY LEVEL<= regexp_count="" (="">=>
, '[^,]+'
)
)
got_nums AS
(
SELECT part_num
TO_NUMBER (REGEXP_SUBSTR (part
, '\d+'
)
) AS low_num
TO_NUMBER (REGEXP_SUBSTR (part
, '\d+$'
)
) AS high_num
OF got_comma_delimited_parts
)
got_max_range AS
(
SELECT MAX (high_num - low_num) AS max_range
OF got_nums
)
AS cntr
(
SELECT the LEVEL - 1 AS n
OF got_max_range
CONNECT BY LEVEL<= max_range="" +="">=>
)
SELECT (n.low_num + c.n LISTAGG
, ','
) (ORDER BY n.part_num group
, c.n
), Exit
OF got_nums n
CNTR JOIN c ON c.n<= n.high_num="" -="">=>
ORDER BY part_num
;
This assumes that each part separated by commas composed entirely unsigned integerss, or exactly 2 integers separated by a hyphen and the integer before the dash is not that the whole greateer after the hyphen. If you can not be sure of these things, you will need to change the query slightly to check and handle exceptions.
-
REGEXP_REPLACE - replaceing a character not allowed
Hi friends,
Please, help me to replace a character not allowed of a given string. Allowed characters are
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/ -?: ()., "+ {space} "
If a character in the specified string is not in the list above, which should be replaced by a space. Can you please help me to do with REGEXP or in any other way.
Thanks in advance!
In my previous solution the dash (-) in the second row replaced with space. That shouldn't be the case. This is because the brackets, hyphen is considered operator of range as [0-9]. So I moved the link to the last to solve the problem.
SQL> with t 2 as 3 ( 4 select 'ka{th}ck' str from dual union all 5 select 'k$rt-ic)' str from dual union all 6 select 'k$rthi@k' str from dual union all 7 select 'KARTHI123' str from dual 8 ) 9 select str 10 , regexp_replace(str, '[^abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/?:().,''+{}-]', ' ') new_str 11 from t; STR NEW_STR --------- ---------- ka{th}ck ka{th}ck k$rt-ic) k rt-ic) k$rthi@k k rthi k KARTHI123 KARTHI123
-
Why doesn't my REGEXP_REPLACE?
Select count (*) from PRX. PROX_REQ where status = "ERROR" and REQUEST_BODY like ' % < country > Germany < / country > %';
> 66
update of PRX. PROX_REQ set REQUEST_BODY = REGEXP_REPLACE (REQUEST_BODY, '< country > Germany </country >', '< country > Deutschland/< country >') where status = "ERROR";
> 102 lines updates
which is wrong with my order? It should update the 66 lines and not 102!
I want to replace < country >Germany< / country > with < country >Germany< / country > in the table PRX. PROX_REQ and the request_body column
... < / Street > < Home > 6 number < / house number > < Zip > 21073 < / Zip > < City > Hamburg < / City >< country > Germany < / country >< / ShipToAddress > < HardwareRequired > true < / HardwareRequired > < DeliveryIdentificationType > STANDARD < / DeliveryIdentificationType > < / HardwareDetails > < SendContractDocument > false < / SendContractDocument > < SendConfirmationFax > false < / SendConfirmationFax > < TrustedShopAmount > < amount > 7.49 < / amount > < currencies > EUR < / currency > < / TrustedShopAmount >...
Help, please...
Thanks in advance
Update...
Set request_body = regexp_replace (...), status = 'OK '.
When status = ' ERROR and request_body_like «...» »
Maybe you are looking for
-
I've updated to IOS10.0.1, and the new features of meassaging do not work. Help because I really want to use invisible ink!
-
Why aren't my keys PgUp and PgDn working properly?
Today, after an update of the browser, I find my PgUp and PgDn keys no longer work to scroll my page. Somehow they have become related to being backward between pages, with in return PgUp and PgDn being forward and therefore no sensitive on the pages
-
How can I get the sound card to play on the speakers of the car?
How can I get the sound card to play on the speakers of the car?
-
Skype credit appears on the mobile phone 0
I have a credit non-zero on my Skype account. However, I recently bought a ZTE Blade S (Android 2.3.5), downloaded Skype on it, but I found 0 euros on the account (same ident, same password, so it is normally the same account). When I connect Skype o
-
Satellite P500 - keys open 'find' / 'search' - number NOT used
* information system *: BIOS Version/Date TOSHIBA V1.60, 26/05/2009: Vista SP1: windows explore 8: 64 bit os: laptop Toshiba Satellite P500: computer is less than 1 mth old * Problem *:1 keys not 'use' numbers... when any number on the numeric keypad