regexp_replace all occurrences

Hi all
I use oracle 10g and am trying to use regexp_replace.

assuming I have a code which is built by the numbers and the letter A, for example: A1A6A2.
the need to drop the occurrences of all 'A' inside, but not the first and not the last.

in other words, the letter A, which takes place between two numbers.

I used the bottom of segments
select regexp_replace('A1A6A2', '(\d)A(\d)', '\1\2')
from dual

select regexp_replace('A1A6A2', '(\d{1,})A(\d{1,})', '\1\2')
from dual
and got this result: A16A2

who not complete necessary given that the result is still letter has between 6 and 2!
is it because that the var is not scanned
I even used it:
select regexp_replace('A1A6A2', '(\d)A(\d)', '\1\2', 1, 0)
from dual
but he got the same results,

The results is supposed to be: A162

How can I replace all instances of the model in the source_char

can help you with tips, advice, or even a link
while I can understand how to regexp to find the expression pattern.

Best regards, thanks in advance.
Anne Marie,

Published by: Knowledgestudent on April 26, 2012 12:08

Hello

I think that one thing to learn about the regexp is to know when not to use.

Your first requirement
"To quit the occurrences of 'A' all the interiors, but not the first not last."

can easily reached by

with t as (
  select 'A1A6A2' s from dual
)

select
  substr(s,1,1)
||replace(substr(s, 2, length(s) - 2),'A', null)
||substr(s, length(s) ,1)
from t

S
A162

your second reuqirement is not at all the same as the first

"in other words, the letter A, which takes place between two numbers.

and it's a little more complicated ;-)

It cannot be DOE with a regexp easy IMHO. Think about it, the regular expression is the first occurrence of \dA\d, for example A1A6A2A3. To do this, replace it. The next character will be an a A, when the model will not match. So it goes for the next, the A is going to stay.

with t as (
  select 'A1A6A2A3' s from dual
)
select
regexp_replace(s,'(\d)A(\d)','\1\2')
from t

REGEXP_REPLACE(S,'(\D)A(\D)','\1\2')
A16A23

concerning

Published by: chris227 on 26.04.2012 01:26

Tags: Database

Similar Questions

  • Remove all occurrences of the string in the string

    Hello.

    We have a problem with the change of all occurrences of a string in string.

    We know how to do the hard, but what would be the easiest?

    We have a string like:

    2014/00212, 2014/12312, 2013/23443 2014/20156

    or simply as

    2014/00212

    or there may be several occurrences of substring in the form xxxx/xxxxxx.

    How can we change channel:

    14/00212, 14/12312, 13/23443 14/20156

    Thank you.

    If I understand you want to replace every 20 at the beginning of each part of the entire string.

    The rooms are separated by a comma and consecutive space. He also begins with this separation.

    The part of the year is separated by a slash from the rest of the part

    Select

    regexp_replace (' 2014/00212, 2014/12312, 2013/23443, 2014/20156 ')

    ', 20'

    ,'\1'

    ) r

    of the double

    R

    ", 14/00212, 14/12312, 13/23443 14/20156.

    or simply

    Select

    Replace (' 2014/00212, 2014/12312, 2013/23443, 2014/20156 ')

    ', 20'

    ,', '

    ) r

    of the double

    R

    ", 14/00212, 14/12312, 13/23443 14/20156.

  • Find all occurrences of a term, through multiple Word documents and examine each instance in its local context (i.e. extracted)

    Hi all

    I'm looking for an easy way to find all occurrences of a term, through multiple Word documents and review of each instance of the word in its local context (i.e. extracted) without having to open each document.

    For example, if I want to search the term "religious atmosphere", the search results would be something like:

    Paper 22: '.. '. but the religious atmosphere had not evolved to the point where... »

    Paper 22: "...". not that the religious atmosphere was still too controversial for a settlement... »

    Document 35: "...". If anything, the religious atmosphere was still little developed for a city... »

    Document 35: "...". it in no way improve the religious atmosphere until the decision was... »

    Paper 42: '.. '. up to - what point, the religious atmosphere was very collegial with all the elements of... »

    Any Microsoft or utility 3 rd-party which can put each instance-by-side and in a context extract would be a real, real help!

    Any ideas?

    Thank you

    Jay

    Ken is perhaps more familiar with the Agent Ransack, I am, but a quick check she finds every instance of a string of text and shows the term in the context of a single line subject to the following:

    • At the end of the search, a list of the files found is accompanied by some statistics.
    • If you select one of the files found, each 'hit' for this file is displayed in the context of a single line.  In other words, you get a list of hits in context as in your original question.  Instead, you get a list of, say, 42 documents and then if you have selected the Document 22, you will see:
      • «.. but the religious atmosphere had not evolved to the point where... »
      • «.. . not that the religious atmosphere was still too controversial for a settlement... »
    • The display of content seems to work with OK * .doc, *.docx and files *.pdf; not so many other types of files - even if it looks for text in all kinds of other files.

    Agent Ransack is free.  Download and try it.  If you don't like, just uninstall.

  • Find and replace all occurrences of a string within the current paragraph.

    I did so much work, and it's my last method to implement.

    I want to get the current active doc the current paragraph and replace all occurrences of a string inside this paragraph with another string.

    For example, say I have the following paragraph in a document:

    «This is a sentence that.» This is another sentence. It is also another sentence. The sentence ".

    If the user opens the document containing the paragraph and goes to this paragraph by clicking in any place in there, I want to replace e.g.g "another punishment" with "phrase.

    But only in the current active paragraph in the active document.

    I found a code with F_ApiFind and F_ApiGetTextRange to get the current text selection, but I can't think of a way to do it.

    Post edited by: Efstathios Chatzikyriakidis

    Problem solved people. Thank you.

  • Expand/retract all occurrences of the text in menu drop-down in a topic

    I was unable to find anything about this is on this issue so please forgive me if I have missed somewhere.

    I'm working on a webhelp in RH0 project which uses a LOT of drop-down text.  One of the problems is that I can't find a way that it is possible to expand or reduce (i.e. + or)-all occurrences of the text in menu drop-down in a topic once it is in WebHelp output.

    Thank you!

    Tests - http://www.grainge.org/pages/authoring/twisty/twisty.htm or http://www.wvanweelden.eu/blog/2013/09/04/expand-selected-drop-downs-default

  • Get all occurrences of a Word.

    Hello

    Is it possible to find all occurrences of a word in a single document using Oracle text?

    Or maybe a count of how many times a word appears in a document?

    I had a glance at the documentation and the web and don't think it is, could anyone suggest a way to do this?

    Thank you very much

    Darren.

    Hello

    You can, as Roger said to use ctx_doc.tokens. This works if you already have a clue (text) on the document. You also have the option to use ctx_doc.policy_tokens. This does not have a clue, but needs a policy. The two proceedings are with examples in the Manual: [url http://download.oracle.com/docs/cd/E11882_01/text.112/e16593/cdocpkg.htm#CEGCIDAJ] package CTX_DOC.

    Herald tiomela
    http://htendam.WordPress.com

  • Regex to replace all occurrences of an empty string, except the last

    Hello, everyone!

    I need get to a regular expression to replace all occurrences of an empty string except the last. Right now I'm doing this with this code:
    public static void main(String[] args)
    {
        String str = "abc";
        String regex = "";
        System.out.println(str.replaceAll(regex, "-").replaceFirst("-$", "")); // -a-b-c
    }
    As you can see, to do this, I have to make two calls: one for replaceAll and another for replaceFirst to get rid of the last character. So I would like to get rid of the call to replaceFirst and have the variable of regex as being a regular expression that would be to insert the character along the chain of all but the last. I'm really not very good with regexs, so I ask your help here. The thing I work, but I think it would be more elegant with just a regex to do.

    Thank you in advance.

    Marcos

    Try this:

    String data = "abc";
    System.out.println(data.replaceAll(".", "-$0"));
    
  • Returns all occurrences of a substring

    Hello
    I have a problem with the reference to the data in a list.
    I can contain the values of the fields such as (going after MTC):

    * MOCS13; MTCIN13; MTCIN14; 100-14; 111 IN IN 14; 123 14
    * MTCIN13; MTCIN14; 100-14; 111 IN IN 14; 123 14
    * MOCS13; MTCIN13; MTCIN14
    * MOCS13; M100IN14; 111 TO 14; 123 IN 14
    * ...


    * MTCXXX can have different sizes and can be anywhere in the area.
    * The cams of information in a list, so it is ordered, if there is more then a TCM it will be come to the front.
    * "MTC" is always;


    first of all, I just need to check if the information exists, then I did this:
    Decode (REGEXP_SUBSTR (Upper (Concat(';',List)), Upper(';) MTC ^; +')), NULL, 'FALSE', 'TRUE') AS MTC

    and it was OK

    then there was asked to return the value full and I did this:
    NVL (substr (REGEXP_SUBSTR (Upper (Concat(';',List)), Upper(';) MTC; +')), length(';mtc')-2, length (REGEXP_SUBSTR (Concat ('; ', List),';)) MTC; +'))),' ') IN TCM

    now that I did this, I was told that there may be several occurrences and that I must return all values!
    I ordered the list to make this easy, but I'm not currently in a position to get the right expression to get the set of values!
    can someone help me?

    Thank you
    Ricardo Tomas

    And if you are looking for the same sort of output as input.

    SQL> ed
    Wrote file afiedt.buf
    
      1  with t as (select 'MOCS13;MTCIN13;MTCIN14;100IN14;111IN14;123IN14' as list from dual union all
      2             select 'BOB13;MTCIN23;123IN14' from dual union all
      3             select 'MTCIN11;123IN14;MTC123X' from dual
      4            )
      5      ,t2 as (select list, row_number() over (partition by list order by 1) as pos
      6              from t, (select rownum from dual connect by rownum <= 100)) -- assumes never more than 100 entries in list
      7  select list, ltrim(sys_connect_by_path(mtcs,';'),';') as mtcs
      8  from (
      9    select list, ltrim(REGEXP_SUBSTR(';'||list,';[[:alnum:]]*',1,pos),';') as MTCs, row_number() over (partition by list order by 1) rn
     10    from t2
     11    where ltrim(REGEXP_SUBSTR(';'||list,';[[:alnum:]]*',1,pos),';') like 'MTC%'
     12    )
     13  where connect_by_isleaf = 1
     14  connect by list = prior list and rn = prior rn+1
     15* start with rn = 1
    SQL> /
    
    LIST                                           MTCS
    ---------------------------------------------- ------------------------------
    BOB13;MTCIN23;123IN14                          MTCIN23
    MOCS13;MTCIN13;MTCIN14;100IN14;111IN14;123IN14 MTCIN13;MTCIN14
    MTCIN11;123IN14;MTC123X                        MTCIN11;MTC123X
    
    SQL>
    
  • Replace all occurrences of a particular fon.

    I work with a Muse model that uses a font that I can't access. Muse uses a default font instead. It will take forever to replace all instances of the default font with the new font I want to use. Is there a quick way to find a particular font and replace all instances of it?

    Thanks in advance,

    Glen

    Probably the easiest to set up a new paragraph styles, then apply to all the text you want to change.

  • How to remove all occurrences of Yahoo from my "subject: config ' file?"

    Thanks in advance for any help you can offer.

    Somehow, I hijacked by Yahoo yesterday and ends as my default search provider. And, after that, the small magnifying glass where search engines are listed have disappeared. Firefox doesn't have to feel very safe!

    I restored the search "magnifying glass" through "Customize", but I don't want any more 'surprises' Yahoo

    The next four lines are copied from my "subject: config ' file." Are they necessary?

    browser.search.order.US.1;data:text/plain,browser.search.order.US.1=Yahoo
    Browser.Search.Order.2; Yahoo
    browser.contentHandlers.types.0.uri; https://Add.my.Yahoo.com/RSS?URL=%s
    browser.contentHandlers.types.0.title; My Yahoo!

    In addition, these two:

    gecko.handlerService.schemes.mailto.0.uriTemplate; https://compose.mail.Yahoo.com/?to=%s
    gecko.handlerService.schemes.mailto.0.name; Yahoo! Mail

    browser.search.order.US.1;data:text/plain,browser.search.order.US.1=Yahoo > default search engine. This line is necessary, but you can define a different value to replace Yahoo, Google or Bing for example

    Browser.Search.Order.2; Yahoo > if you use the American version of Firefox, this line is not used

    browser.contentHandlers.types.0.title; My Yahoo! > corresponding to the 1st app/site used when you subscribe to a feed

    gecko.handlerService.schemes.mailto.0.uriTemplate; https://compose.mail.Yahoo.com/?to=%s and gecko.handlerService.schemes.mailto.0.name; Yahoo! Mail > these lines define the 1st element in the list that appears when you open a link mailto: Protocol (i.e. an email address)

    To conclude, except the 1st line, Yahoo does not work on your computer, unless you specifically choose to use when a context menu is displayed.

  • How can I uninstall hidden programs (not shown in Add/Remove Programs)? I already tried to delete all occurrences of 'hide' in sysoc.inf, but programs still do not appear in Add/Remove programs.

    I'm on XP SP2 installed (not enough space for SP3). Hidden programs include MovieMaker, Outlook Express and Internet Explorer (for the last two, add/remove windows components will only remove the links, not the programs themselves). Thank you!

    Hi Mr. Diamond,

    You can't completely remove or uninstall programs like Movie Maker, Outlook Express or Internet Explorer from the computer, because these were built in operating systems.

    If you want to free up space on the computer, and then see the link below.

    http://www.Microsoft.com/atwork/maintenance/speed.aspx

  • REGEXP_REPLACE problem/bug - replaces only each second occurrence

    Hi all


    I use

    Oracle Database 10 g Express Edition Release 10.2.0.1.0 - product
    PL/SQL Release 10.2.0.1.0 - Production
    CORE 10.2.0.1.0 Production
    AMT for 32-bit Windows: Version 10.2.0.1.0 - Production
    NLSRTL Version 10.2.0.1.0 - Production

    I need a regular expression to rename a variable in a mathematical formula, when testing my code that I discovered that if the variable was repeated after himself that a single occurrence has been replaced. I need to replace only whole words as some variables can be a subset of a variable name longer, and variable names can have underscores in them.
    Here is an example of what happens.

    Is someone can you please tell me why this happens? Example code is:

    SELECT REGEXP_REPLACE (' ab ab ab + ab + ab + ab + ab + abc + abc + ab ", '(\W|^)ab(\W|$)', '\1xy\2',1,0,'i') from DUAL;

    The regular expression matches all the "ab" with a start line or a non alphabetical character before and not alpha or end of line at the end.

    I have then replace the "ab" by "xy" and keep the original alpha not on each side. What happens is that only every second occurrence is replaced.
    If I put a space after each '+', and then it replaces all occurrences. (Of course, this is a domain user in a table of mathematical formulas so I can not wait to the user to worry about this problem.)

    I think that this may be due to the fact the pointer in conclusion any occurrence is moved correctly and it does not find the game immediately after.

    Can someone please explain this? Or did I miss something in my example.

    Thank you
    Dudley

    I don't think it's a bug, at least comparable re in python produces the same result:

    import re
    s="ab+ab+ab+ab+ab+ab+ab+abc+abc+ab"
    print re.sub(r"(\W|^)ab(\W|$)",r"\1xy\2",s)
    xy+ab+xy+ab+xy+ab+xy+abc+abc+xy
    

    If you have a match in your regular expression, the next probe will be launched after the game, it's how the regular expression works (at least IMHO).
    In your example the corresponding characters are "+ ab + (except the beginning of the line, end of line), that's why next occurency"ab"is not equal to."
    If you want to replace all"in Alberta, you could make the model as

    SELECT REGEXP_REPLACE('ab+ab+ab+ab+ab+ab+ab+abc+abc+ab', '(\W|^)?ab(\W|$)' , '\1xy\2',1,0,'i') from DUAL;
    

    Best regards

    Maxim

    Published by: Maxim Demenko, 14 July 2009 14:09
    fixed formatting

  • 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]
    • \) 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.
  • A question about regexp_replace

    Convert the string "This is a test" to "This is a test" using backreference expression


    db > select regexp_replace('This is a test', '(^[[:alpha:]]+) ([[:alpha:]]{2})', '\2......\1') OUTPUT from dual;
    OUTPUT
    -------------------
    is......This a test
    

    Fell on the regular expression above and after having made a few of them, this one threw me. It was on paper and the response that works leaves scratching me my head as to why it works at all.

    (^ [[: alpha:]] +)

    I interpret this as saying... .to find the start of a string of alpha one or several characters in this case "it."

    ([[: alpha:]] {2})

    and I interpret this As... to the point that expression (^ [[: alpha:]] +) had stopped, look for alpha pair "istest".

    and then swap them... 'istestThis '.

    I'm obviously completely wrong interpret this so any help appreciated.

    ' (^ [[: alpha:]] +)'(^[[:alpha:]]+)

    (^ [[: alpha:]] +)

    (^ [[: alpha:]] +)

    Hello

    Gusora wrote:

    DB > select regexp_replace ('This is a test', ' ([[: alpha:]] {2})', 'x') twice;

    REGEXP_RE

    ---------

    x xx a xx

    When you call REGEXP_REPLACE with onoy 3 arguments, then all occurrences of the 2 argument will pass to the argument 3.

    How many times is the model ' ([[: alpha:]] {2})' occur in "this is a test"?  5 times.

    1. "Th".
    2. 'East' (starting at position 3)
    3. 'East' (starting at position 6)
    4. 'you' and
    5. "st."

    all match the pattern ' ([[: alpha:]] {2})', so they are all replaced by 'x '.

    So, how ' ([[: alpha:]] {2})' operates here where he will continue to search until the end of the string is different in the way that works in the following expression...

    DB > select regexp_replace ('This is a test', ' (^ [[: alpha:]] +) ([[: alpha:]] {2})', '\2 \1') of double;

    REGEXP_REPLACE

    --------------

    is this a test

    How many times is the model "(^[[:alpha:]]+) ([[: alpha:]] {2})' occur in 'This is a test'?"  Only 1 time.  ' ^' means 'at the beginning of the string", and there is only 1 starting at the chain.  "a you ' does not match the model because" one you "does not occur at the beginning of the string.

  • Replace or remove all single line breaks in a Blob

    Hello

    I want to remove/replace all new simple lines (NOT the carriage return / new line) in a BLOB.

    I tried to convert the BLOB in a clob, and then replace all occurrences of new lines of simple with the function replace (for example replace (clob, 10),)
    I even cut the clob into small pieces of varchar2 and tried to apply the function replace etc., but without success!

    I'd be happy if someone could give me a tip how I could fix this problem.

    I use
    Request 4.1.0.00.32 Express on
    Oracle 10g (10.2.0.4.0 - 64 bit)

    Thank you
    Johnny

    Johnny Be Good wrote:
    Hi Paul,.

    the answer to your first question is simple. I use a blob instead of a clob object because I download a file (csv) using an element "Browse file".
    The file is then stored in FLOWS_FILES. WWV_FLOW_FILE_OBJECTS$ (wwv_flow_files) that stores the file in a blob (blob_content) column.

    What to do now is to store the contents of the BLOB to a file in a directory in order to to use as an external file.
    After this, I question the external file and merge the contents into a normal table within the database.

    The problem I have now is that sometimes downloaded csv files have 'broken data sets' in the way that a line (a single dataset), which was divided into
    two or more rows (with a single line break at the end of each line instead of a carriagereturn/linefeed to the normal lines).
    Sometimes, when the lines matching/data sets contain a very large text (e.g. 3000 characters) in a single column and MS excel (the tool used to record the original excel in csv file) can not handle this long texts of a column and breaks the content of a line into multiple lines in a cell.

    However, I need to "Break" the broken data sets in the blob downloaded by removing (or replace) single line breaks, which are an indication of a split data set.

    In view of this process. I converted to CLOB BLOB when the file is extracted from APEX_APPLICATION_FILES, remove the EPA of the problem, and then write in the file system as a CLOB.

    I tried to do by converting the BLOB in a clob, for example with this function:

    A function like this is reinventing the wheel. 10g comes with dbms_lob.convertToClob (see above).

    And after conversion, trying to replace all the occurrences of single line within this clob breaks, for example with this code:

    l_clob := replaceClob(l_clob,chr(10),' ');
    

    Who will replace all the LFs, whether or not they are in CR/LF pairs. Use regexp_replace/regular expressions to exclude EPA following a CR (see above).

    "Without success" means, that the line breaks have not been replaced. I tried several ways as delete (replace without a third parameter and the corresponding function), replacement (for example with a white) etc. !

    I even tried to apply the function of standard replacement for varchars on a clob that I read somewhere that it is supported in 10g and apex 4.1 but with the same result.

    I think that you have been making life difficult for yourself. Everything that seems to involve more (ineffective) writing code as necessary. Everything you need is built into 10g (it seems that you could use the obsolete references?)

    I hope I could explain the question a bit better now and would appreciate it if you had a starting point for me.

    Should have what you need in the above examples.

Maybe you are looking for

  • product key Windows 8.1

    I just bought a laptop HP from PC world with 8.1 Windows preinstalled. I have however no disc or product key. Could you please tell me if I need to activate Windows or how I would manage if I ever needed again to install windows 8.1 in the future wit

  • CQ61: System Recovery (System power)

    This laptop was given to me without a power supply, I had one but it will only charge the battery so I can run the pc.  I'm trying to restore the system, but when I start the restore process it won't let me because it says on its battery power.  But

  • Just made anti-virus Malwarebyte s scan on my laptop and need some advice please...

    When the scan has finished a very long list of problems came, there was an option to remove the problems individually or completely, it would be safe just to delete the lot or it might cause problems, I would really advice you can give me...

  • Use disk abnormality

    The Windows 7 Explorer shows 123 GB of files and folders on drive C.  However, the total of all records on the subject comes to 37.6 GB.  Y at - it an explanation for that?  Is there anything I should do?

  • BlackBerry Smartphones Pac - Man by Namco on the Web, but not in application on phone

    I want to buy Pac - Man by Namco through App World.  I find that when I go to App World on the Web, but it does not when I use the latest App World app on my phone (I just downloaded the latest version of App World today).  How can I buy it?