Regular Expression/Replace - Oracle 7.3
Hi!
I am trying the regular expression SQL functions of 10g to Oracle 7.3 and it seems the older version does not cover this feature yet.
"Aaaa,Bbbb" --> "Aaaa, Bbbb"
REPLACE *",[0-9A-Za-z]"* WITH *", "*
The string pattern is to look for comma-punctuations that is not followed immediately by whitespacess so I can replace this with a comma followed by a whitespace.
Any workaround for this?
Hi,
Welcome to the forum!
kitsune wrote:
Hi!
I am trying the regular expression SQL functions of 10g to Oracle 7.3 and it seems the older version does not cover this feature yet.You're right; regular expressions only work in Oracle 10.1 and higher.
>
>
"Aaaa,Bbbb" --> "Aaaa, Bbbb"
REPLACE *",[0-9A-Za-z]"* WITH *", "*
The string pattern is to look for comma-punctuations that is not followed immediately by whitespacess so I can replace this with a comma followed by a whitespace.
Any workaround for this?You're best bet in Oracle 7.3 would be a user-defined function. That's a very old version; don't expect much.
Do you know anything else about the string? For example, is there some character (say ~) that never occurs in the string? Will there ever be two (or more) whitespace characters after punctuation? What characters do you consider to be whitespace? Which are punctuation? Depending on the answers, you might be able to do something with nested REPLACE and/or TRANSLATE functions.
Similar Messages
-
Regular expression vs oracle text performance
Does anyone have experience with comparig performance of regular expression vs oracle text?
We need to implement a text search on a large volume table, 100K-500K rows.
The select stmt will select from a VL, a view joining 2 tables, B and _TL.
We need to search 2 text columns from this _VL view.
Using regex seems less complex, but the deciding factor is of course performace.
Would oracle text search perform better than regular expression in general?
Thanks,
MargaretHi Dominc,
Thanks, we'll try both...
Would you be able to validate our code to create the multi-table index:
CREATE OR REPLACE PACKAGE requirements_util AS
PROCEDURE concat_columns(i_rowid IN ROWID, io_text IN OUT NOCOPY VARCHAR2);
END requirements_util;
CREATE OR REPLACE PACKAGE BODY requirements_util AS
PROCEDURE concat_columns(i_rowid IN ROWID, io_text IN OUT NOCOPY VARCHAR2)
AS
tl_req pjt_requirements_tl%ROWTYPE;
b_req pjt_requirements_b%ROWTYPE;
CURSOR cur_req_name (i_rqmt_id IN pjt_requirements_tl.rqmt_id%TYPE) IS
SELECT rqmt_name FROM pjt_requirements_tl
WHERE rqmt_id = i_rqmt_id;
PROCEDURE add_piece(i_add_str IN VARCHAR2) IS
lx_too_big EXCEPTION;
PRAGMA EXCEPTION_INIT(lx_too_big, -6502);
BEGIN
io_text := io_text||' '||i_add_str;
EXCEPTION WHEN lx_too_big THEN NULL; -- silently don't add the string.
END add_piece;
BEGIN
BEGIN
SELECT * INTO b_req FROM pjt_requirements_b WHERE ROWID = i_rowid;
EXCEPTION
WHEN NO DATA_FOUND THEN
RETURN;
END;
add_piece(b_req.req_code);
FOR tl_req IN cur_req_name(b_req.rqmt_id) LOOP
add_piece(tl_req.rqmt_name);
END concat_columns;
END requirements_util;
EXEC ctx_ddl.drop_section_group('rqmt_sectioner');
EXEC ctx_ddl.drop_preference('rqmt_user_ds');
BEGIN
ctx_ddl.create_preference('rqmt_user_ds', 'USER_DATASTORE');
ctx_ddl.set_attribute('rqmt_user_ds', 'procedure', sys_context('userenv','current_schema')||'.'||'requirements_util.concat_columns');
ctx_ddl.set_attribute('rqmt_user_ds', 'output_type', 'VARCHAR2');
END;
CREATE INDEX rqmt_cidx ON pjt_requirements_b(req_code)
INDEXTYPE IS CTXSYS.CONTEXT
PARAMETERS ('DATASTORE rqmt_user_ds
SYNC (ON COMMIT)'); -
Hello All,
I come from Perl scripting language background. Perl's regular expressions are rock solid, robust and very fast.
Now I am planning to master Regular Expressions in Oracle.
Could someone please point the correct place to start with it like official Oracle documentation on Regular Expressions, any good book on Regex or may be any online link etc.
Cheers,
Parag
Edited by: Parag Kalra on Dec 19, 2009 11:03 AMHi, Parag,
Look under [R in the index of the SQL language manual|http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/index.htm#R]. All the regular expression functions and operators start with "REGEXP", and there are a couple of entries under "regular expressions".
That applies to the Oracle 11 and 10.2 documentation. Regular expressions were hidden in the Oracle 10.1 SQL Language manual; you had to look up some similar function (like REGR_SYY, itself hidden under S for "SQL Functions", and then step through the pages one at a time.
Sorry, I don't know a good tutorial or introduction.
If you find something hopeful, please post a reference here. I think a lot of people would be interrested. -
Regular expressions in oracle 10 g
how to use regular expressions in oracle 10g forms
May be forms related question better answered in forms forum.
Forms -
Regular expression - Replace not like
Hi All,
Is there a regexp pattern to replace anything other than 'oracle' from the below string.
"oracle sdsd oracle xyd fgh oracle idmdh asasas trtrt"
The result will be "oracleoracleoracle"
If I want to write like regexp_replace('oracle sdsd oracle xyd fgh oracle idmdh asasas trtrt',<pattern>), what should be the pattern?
I know how to get the result by nesting regexp and other functions.
But is there any single pattern for this?
Thanks in advance.
Note; This is not a business requirement, trying to learn regexp..884476 wrote:
Could you please explain what does that pattern mean? We can look at your string as a sequence of substrings where each substring is set of characters (part A) followed by word oracle or, in last substring, by end-of-line (part B). Each of such substrings be want to replace with part B thus removing part A.
Dot (.) means any character. Asterisk (*) means repeated 0 or more times. This is our part A (I'll get back to ? later). Pipe (|) means OR. Dollar sigh ($) means end-of-line. Parenthesis mean grouping. So ((oracle)|$) means string oracle or end-of line. This is our part B. Now back to question mark. By default Oracle regular expressions are "greedy". We say any character repeated any number of times followed by word oracle. Since word oracle itself matched definition of any character repeated any number of times (6 in this case) regexp will match it that way that it will be from the beginning of the string to last occurrence of word oracle - that's why it is called "greedy". Question mark (?) tells regexp not to use greedy matching, therefore '.*?oracle' will stop at first occurrence of word oracle. Now replacement string. Notation \1 is grouping backreference. Group 1 is ((oracle)|$) and, as I already noted, means string oracle or end-of line (whichever was found).
SY. -
Regular expressions in Oracle 9i
Hello,
Does oracle 9i support regular expressions?
I need to check if a varchar parameter contains only numbers OR letters, otherwise i should return false.
Thanks.Roger22 wrote:
Hello,
Does oracle 9i support regular expressions?
I need to check if a varchar parameter contains only numbers OR letters, otherwise i should return false.
Thanks.TRANSLATE is helpful to do such a check.
example
WITH testdata AS
(SELECT 'abcdef' txt FROM DUAL UNION ALL
SELECT '1234567' txt FROM DUAL union all
SELECT '0' txt FROM DUAL union all
SELECT '123a4567x00' txt FROM DUAL union all
SELECT '123.4567,00' txt FROM DUAL
select txt,
translate(txt,'a1234567890','a') numbers_removed,
translate(txt,'0abcdefghijklonopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ','0') letters_removed
from testdata;
TXT NUMBERS_REMOVED LETTERS_REMOVED
abcdef abcdef
1234567 1234567
0 0
123a4567x00 ax 123456700
123.4567,00 ., 123.4567,00One idea is to check the result for NULL or to compare the length of similiar expressions.
Problems are usually special chars and how you want to handle that.
Edited by: Sven W. on Aug 11, 2010 11:07 AM
Edited by: Sven W. on Aug 11, 2010 11:07 AM -
Regular expression in oracle for hypen
Hi,
I want to match a word "{color:#993300}83-ASG{color}" using regexp_like and i used '{color:#993300}^83-*{color}' pattern to match this word but this also matches words like "{color:#993300}8307-YUF{color}". could anyone please tell me what pattern should i use to match words like {color:#993300}83-ASG{color}.
Also i need to know the similar pattern in oracle for the "{color:#993300}\b{}{color}" used in .net.
Thanks in advance.
PrasadHi Prasad,
Your regex could be as simple as '^83-'
So, not much use for a regular expression:
SQL> with test_data as (select '83-ASG' txt from dual union all
select '8307-YUF' from dual)
-- end of test data
select txt from test_data
where txt like '83-%'
TXT
83-ASG
1 row selected.Unless, you add some more value to it, perhaps like
SQL> with test_data as (select '83-ASG' txt from dual union all
select '8307-YUF' from dual)
-- end of test data
select txt from test_data
where regexp_like(txt, '^83-[[:upper:]]{3}$')
TXT
83-ASG
1 row selected.Regards
Peter -
Regular Expression replacement not working
I am trying to use a regular expression to replace non-ascii characters on a file, and I'm afraid I've reached the end of my regex knowledge.
Here is the specific code
'Set the Regular Expression paramaters
Set RegEx = CreateObject("VBScript.Regexp")
RegEx.Global = True
RegEx.Pattern = "[^\u0000-\u007F]"
RegEx.IgnoreCase = True
'Replace the UTF-8 characters
ReplacedText = RegEx.Replace(FileText, "\u0020")
If I understand regular expressions correctly the pattern of "[^\u0000-\u007F]" should replace any character that is not an ascii character, and then replace it with a space (which I understand is "\u0020"). What am I doing wrong?Simply use
ReplacedText = RegEx.Replace(FileText, " ")
Regards, Hans Vogelaar (http://www.eileenslounge.com) -
Regular Expression / replace Function Help
The problem:
cfset myString = "i am a big boy"
cfset outputString = replace("i am a big
boy","i","you","all")
Wrong Output:
you am a byoug boy
Intended Output
you am a big boy
How do I achive that output.Your first example had only one sentence. That's why I gave
that answer.
Anyway for your real question, you need to use regular
expressions
#rereplace(myString,"i\s","you ","all")# - will give u
you am a big boy you am a big boy you am a big boy you am a
big boy.
\s looks for a whitespace character after the letter i. So
that way it will not change the letter i in big -
Regular Expressions - replace inner group
I'm trying to do the following:
1. Given the following string:
Truth, like tumors, require a cut to be removed.
2. Grab the whole sentence and the following:
like tumors
3. Replace "like tumors" with "like posion" and add one line to the sentence like so:
Truth, like posion, require a cut to be removed.
To be free you must endure pain for a season to finally be free from it.
I can grab the sentence with reg expressions, I can even grab the second search (#2) in a group, I'm just wondering if there is an elegant way to replace both at the same time. I could always replace one then search and replace the next, but that seems redundant since I can grab both the first time around. Any help?according to:
http://javaalmanac.com/egs/java.util.regex/GroupInRep.html?l=find
// Compile regular expression
String patternStr = "\\((\\w+)\\)";
String replaceStr = "<$1>";
Pattern pattern = Pattern.compile(patternStr);
// Replace all (\w+) with <$1>
CharSequence inputStr = "a (b c) d (ef) g";
Matcher matcher = pattern.matcher(inputStr);
String output = matcher.replaceAll(replaceStr);
// a (b c) d <ef> gthis should be exactly what you're looking for. -
How to use regular expression replace for this special characters?
hi,
I need to replace the below string, but i couldnt able to do if we use the special charaters '+', '$' . can anyone suggest a way to do this?
select REGEXP_REPLACE('jan + feb 2008','jan + feb 2008', 'feb',1,0,'i') from dual
anwers should be :- febyou should use escape character \.
the regular expression will look like as follows:
select REGEXP_REPLACE('jan + feb 2008','jan \+ feb 2008', 'feb',1,0,'i') from dual
hope this is what you needed.
cheers,
Davide -
Regular expression - Replace a part of an expression
Dear All,
This is not a business requirement, just trying to practice regexp.
Suppose we want to replace a part of a regular expression from a string. As an example, in the string 'THIS Number 124356 Is to Change.This Number 5 Also', I am trying to replace the last digit of each number with $ sign.
Output will be
'THIS Number 12435$ Is to Change.This Number $ Also'.
Will this be possible using a single regexp_replce?
Thanks in advance.MichaelS wrote:
I am trying to achieve this using a SINGLE regexp_replace.Here we go:
SQL> with t as (
select 'ABC124556def568gh236klJ258' str from dual union all
select 'THIS Number 124356 Is to Change.This Number 5 Also' str from dual
select str, regexp_replace(str, '(\d{0,})\d{1}', '\1$') str2
from t
STR STR2
ABC124556def568gh236klJ258 ABC12455$def56$gh23$klJ25$
THIS Number 124356 Is to Change.This Number 5 Also THIS Number 12435$ Is to Change.This Number $ Also
2 rows selected.
Nice..
Learning for me ..
Never thought of usage like {0,} ... kepping the end value OPEN.
I was trying with \d+?\d, which was not working.. -
(<PartName>([a-z]))(.*)(</PartName>)
I need to change all copy within the <PartName></PartName> tags with Sentence Case. Above selects all the copy that doesn't have a capital.
To write the above out in find and repalce, I would just use $1$2$3$4 but I need the $2 to be a Capital.
What's crazy is that this would seem to be a fairly common thing to do yet finding an answer is nearly impossible. I even have OReilly's Regular Expression Cookbook book and there's nothing in it about replacing text with changed text.
I've been on this for a day now and it's getting to the point where I could have gone through and done it manually in less time.
Sorry for the rant...I gave up and just exported out from my xml into Excel and did a formula there...
-
Need regular expression for oracle date format 'DD-MON-YYYY'
Hi,
Can anybody tell me the regular expression to validate date in 'DD-MON-YYYY'.
My concept is i have a table with just two columns item_name and item_date
Both fields are varchar2 and i want to fetch those records from this table which have valid date format('DD-MON-YYYY').If it must be a regexp, this is a starter for you, note it carries the caveats mentioned by both posters above and in the linked thread
mkr02@ORA11GMK> with data as (select '10-jan-2012' dt from dual
2 union all select '10-111-2012' from dual
3 union all select 'mm-jan-2012' from dual
4 union all select '10-jan-12' from dual)
5 select
6 dt,
7 case when regexp_like(dt,'[[:digit:]]{2}-[[:alpha:]]{3}-[[:digit:]]{4}','i') then 1 else 0 end chk
8 from data
9 /
DT CHK
10-jan-2012 1
10-111-2012 0
mm-jan-2012 0
10-jan-12 0It will not validate content, only string format.
And to emphasis the points made in the linked thread - dates in text columns is poor design. Always. -
Without using a regular expressions in oracle 9i
dear all;
I have the following test data below
insert into p
(id)
values
('\G1\G2');
insert into p
(id)
values
('\A1\');
insert into p
(id)
values
('\B1\B2\B3');
insert into p
(id)
values
('\J1\J2\J3\J4');and this is the output I desire though
ID
G1
null
B2
J3the output is gotten by looking at the second to the last entry and extracting it....
so for \G1\G2 the second to the last entry was G1 hence we have G1
for \A1\ there is no second to the last entry and that is why it is null
for \B1\B2\B3 the second to the last entry was B2Hi,
user13328581 wrote:
... the output is gotten by looking at the second to the last entry and extracting it....
so for \G1\G2 the second to the last entry was G1 hence we have G1
for \A1\ there is no second to the last entry and that is why it is nullSo backslashes at the end of id don't matter. Whether id is
'\AI',
'\A1\' or
'\A1\\\\\\\\\\\\'
there's only entry in id, and so you want to return NULL. Is that right?
Here's one way to do that in Oracle 9:
WITH got_pos AS
SELECT id
, INSTR ( RTRIM (id, '\')
, -1
, 2) + 1 AS pos_from
, INSTR ( RTRIM (id, '\')
, -1
, 1) AS pos_to
FROM p
SELECT id
, CASE
WHEN pos_from > 1
THEN SUBSTR ( id
, pos_from
, pos_to - pos_from
END AS penult
FROM got_pos
ORDER BY id
;
Maybe you are looking for
-
Sync part of address book but not all... how?
Just started using iSync though I've been using my cell and Mac for many years (i.e. newbie at syncing though proficient with Macs). How can I sync part of my Mac's Address Book without including all 600+ contacts? It's a pain to have to scroll throu
-
Why I'm happy I bought a Verizon iPhone... and not At&t
For years, my brothers (and we are all adults... very mature... haha) have rubbed their iphones in my face... always showing me how much better their phones were than mine. They kept taunting me asking why I didn't get an iphone... and then smacked
-
New Ipod not updating or been seen by Itunes
Yesterday I bought a new black Ipod Nano to replace the one that got broken in a freak accident. I plugged in the new Nano into my PC, go the popup stating the software on the Ipod needed to be updated. So I went ahead and ran the Ipod Updater. Then
-
How to dislay images stored in R/3 as archive objects
Dear All, In my view I need to show photos,which are actually uploded into R/3 through archive objects.I have used FM:<b>SCMS_DOC_URL_READ</b> to get the URL, as this is not a http url the image UI element is not render . so pls help me
-
HT201335 How to connect an iphone 5 to apple tv?
How can i share from iphone 5 to apple tv?