REGEXP_REPLACE - remove words

Hi everybody,
I have a quite tricky problem and I hope someone can help...
Imagine the following set of data:
WITH my_data AS
   SELECT 'abc.1.fil' as x FROM dual
    UNION ALL
   SELECT 'def.ol.fil' FROM dual
    UNION ALL
   SELECT 'ghi.ijk.olfil' FROM dual
    UNION ALL
   SELECT 'mno.12.olfil' FROM dual
    UNION ALL
   SELECT 'abc. .fil' as x FROM dual
SELECT  
  REGEXP_REPLACE(x, '(.*)(.ol.fil|.fil|.olfil)$', '\1')
FROM my_data;I need to remove from the end of the string the patterns .fil; .ol.fil and .olfil. But, I don't have the right result with my expression. In this case instead of having this:
abc.1
def
ghi.ijk
mno.12
abc. I'm having this:
abc.1
def.ol
ghi.ijk.o
mno.12.o
abc. Any suggestion? I'm using Oracle 10.2.
Thanks,

You could do the following:
SQL> WITH my_data AS
  2  (
  3     SELECT 'abc.1.fil' as x FROM dual
  4      UNION ALL
  5     SELECT 'def.ol.fil' FROM dual
  6      UNION ALL
  7     SELECT 'ghi.ijk.olfil' FROM dual
  8      UNION ALL
  9     SELECT 'mno.12.olfil' FROM dual
10      UNION ALL
11     SELECT 'abc. .fil' as x FROM dual
12  )
13  select trim(replace(replace(x,'.fil'),'.olfil')) as cleaned
14  from my_data;
CLEANED
abc.1
def.ol
ghi.ijk
mno.12
abc.
SQL>And if you want absolutely to use regexp, you can issue:
WITH my_data AS
   SELECT 'abc.1.fil' as x FROM dual
    UNION ALL
   SELECT 'def.ol.fil' FROM dual
    UNION ALL
   SELECT 'ghi.ijk.olfil' FROM dual
    UNION ALL
   SELECT 'mno.12.olfil' FROM dual
    UNION ALL
   SELECT 'abc. .fil' as x FROM dual
select trim(regexp_replace(x,'(.fil|.olfil)')) as cleaned
from my_dataHere's the execution of the last query:
SQL> WITH my_data AS
  2  (
  3     SELECT 'abc.1.fil' as x FROM dual
  4      UNION ALL
  5     SELECT 'def.ol.fil' FROM dual
  6      UNION ALL
  7     SELECT 'ghi.ijk.olfil' FROM dual
  8      UNION ALL
  9     SELECT 'mno.12.olfil' FROM dual
10      UNION ALL
11     SELECT 'abc. .fil' as x FROM dual
12  )
13  select trim(regexp_replace(x,'(.fil|.olfil)')) as cleaned
14  from my_data;
CLEANED
abc.1
def.ol
ghi.ijk
mno.12
abc.
SQL>Edited by: Manguilibè KAO on 6 févr. 2012 02:19

Similar Messages

  • How to remove words which consist of max 2 letters?

    Hi everybody,
    Is it possible to remove words from string which consist of max 2 letters using REGEXP_REPLACE?
    For example string is 'aa bbb cc dddd' and result should be ' bbb dddd' (3 spaces) or 'bbb dddd' (1 space). It does not matter which one of results.
    Or exists another method to achieve this?
    Thank you.
    Matus.

    Try this.. should work for even punctuations and digits etc.
    It might be done more simpler but this is my try.
    Combined Anthony Wilson and Tom kyte:-)
    WITH t AS
         ( SELECT 'aaa''123 bb cc dddd l mmmm' l
            FROM DUAL )
    SELECT     MAX ( SYS_CONNECT_BY_PATH ( word, ' ' )) scbp
          FROM ( SELECT word, ROWNUM rn
                  FROM ( SELECT    REGEXP_SUBSTR ( l
                                                 , '[[:alpha:][:graph:]]+'
                                                 , 1
                                                 , LEVEL
                                                 ) word
                              FROM t
                        CONNECT BY LEVEL <=
                                        LENGTH ( REGEXP_REPLACE ( l, '[^ ]', '' ))
                                      + 1 )
                 WHERE LENGTH ( word ) > 2 )
    START WITH rn = 1
    CONNECT BY PRIOR rn = rn - 1G.

  • [solved] Remove words from file using a list variable?????

    Is it possible with bash, to create a script that will scan a text file and remove words that are set in a list?
    I have a file with words like so:
    word1
    word2
    word3
    I would like to be able to set script to scan file and remove only the words (and spaces left) that are in a list,
    that is inside script. Is this possible???
    Last edited by orphius1970 (2010-04-22 12:05:45)

    sorry I am new to scripting and Have NEVER used sed.
    Can you explain a little better?
    Ok i tried it and understand a little better. However,
    It left space behind. How do I fix that?
    Also, how do I get it to save the file with the changes?
    Sorry If I seem so noobie
    Last edited by orphius1970 (2010-04-22 11:27:18)

  • Remove words from file

    Hello, I have created a class which is supposed to be an array of stopwords (words that I want to remove from a file).
    Then I want to create another class which reads in a file. It reads the file. Then it looks through the array of stopwords. If it encounters a word in the file which is the same as the word in the array, it replaces it with nothing.
    I want this class to be separate from the main class so that in the main class,I can specify any file, and the stopwords will be removed. Here is some code, thanks
    import java.io.*;
    import java.util.*;
    public class StopWordArray {
         //This class represents an array of stopwords
         //The stopwords are read from a text file into an array
         private String [] tokens;
         //constructor
        public StopWordArray(){          
             try{
    //         open input stream
             File inputFile = new File("/home/myrmen/workspace/Chisquare/extract/stopWordList.txt");
             InputStream inStream = new FileInputStream(inputFile);
             InputStreamReader inreader = new InputStreamReader(inStream, "8859_1");
             BufferedReader reader = new BufferedReader(inreader);
            String line;
            //Fills array
            while ((line = reader.readLine()) != null) {
            StringTokenizer st1 = new StringTokenizer(line);
            int numberOfElements = st1.countTokens();
             tokens = new String[ numberOfElements ];
            int index = 0;
             while( st1.hasMoreTokens() )
               String element = st1.nextToken();
             tokens[ index ] = element;
                       index ++;
            reader.close();
           catch (Exception ex) { ex.printStackTrace(); }
    import java.io.*;
    import java.util.StringTokenizer;
    public class RemoveStop {
         //Fields
         private StopWordArray myArray = new StopWordArray();
        private String myString;
         //Constructor
        public RemoveStop(String myString){
    import java.io.*;
    public class Main {
         public static void main(String[] args) {
              StopWordArray theWords = new StopWordArray();
            theWords.printArray();
            String file = "/home/myrmen/workspace/Chisquare/extract/Turing";
            RemoveStop remove = new RemoveStop(file);
    }

    Ok, here is an update:
    private String [] tokens;
       //Method which returns each element in the array as a string
        public String word()
        String word = null;
        for(int i = 0; i < tokens.length; i++)
        word = tokens.toString();     
    return word;
    public void readFile(){
    String output = null;
    StringTokenizer st1 = new StringTokenizer(aString);
    while(st1.hasMoreTokens())
    String element = st1.nextToken();     
    //System.out.println(myArray.word());
    if(element.equals(myArray.word()))
    output = element.replaceAll(myArray.word(), "WAY");
    //else{System.out.println("ERROR");
    System.out.println(output);
    But with the readFile() method, I only access the LAST element of the array. How can I iterate through the whole array, and search for the words that are stored in the array in the input file?

  • How to remove words you saved in dictionary (symbi...

    Step 1: Download the symbian application (sExplorer.SIS) to your computer.
    Step 2: Bluetooth and install the application (sExplorer.SIS) to your symbian version 3 phone.
    Step 3: After installation completed successfully, please go to "Menu" => "My own"
    Step 4: Select "SExplorer"
    Step 5: Select "C: " by pressing the down key on your phone.
    Step 6: After "C: " is highlighted, press the right key on your phone.
    Step 7: Select "Predic" by pressing the down key on your phone.
    Step 8: After "Predic" is highlighted, press the right key on your phone.
    Step 9: Select *.dat file by pressing the down key on your phone.
    Step 10: Click on the "Options".
    Step 11: Select "Delete".
    Step 12: Select "Yes" when prompt "Delete selected file Are you sure?"
    Step 13: Select "Exit".
    Step 14: Switch off the phone to enable a reboot.
    Step 15: Switch on your phone, the dictionary issue will be resolved!
    EDIT: removed linkMessage Edited by damocles on 18-Oct-2006
    12:17 PM

    Shame you cant edit and simply ammend or remove a word rather than deleting everything
    Orange Handsets : Nokia 51 > NK702 (6130) > 6210 > 6310i (silver)> 7210i > 6230 > 6230i (silver) > N80 (silver) > N95-1
    T-Mobile: N96

  • Batch remove word doc pages from library

    Hi,
    I see there are ways to batch remove or add information to word docs and i have successfully removed the cover page from word docs and put into one document.  Is there any way to remove cover and end pages from word docs in a batch?  I need to
    remove the cover pages of over 300 documents and then the last 2 or 3 pages as well.  
    Any suggestions?
    Thanks,
    thupard

    Deleting the first page is no problem, especially if it's in its own Section. Removing pages from the end of the document is likewise no problem in and of itself, but the '2 or 3 pages' isn't something VBA can be left to decide for itself - it needs rules
    that tell it how to decide whether to delete 2 pages or to delete 3 pages. If Section breaks at the end of the document are involved, matters can become complicated when header/footer content and differences in page layout need to be considered.
    Cheers
    Paul Edstein
    [MS MVP - Word]

  • HT2496 How do I remove words from my personal dictionary?

    I added a mispelled word to my Dictionary using the "Add to Dictionary" menu option. I need to remove it now and can't figure out how to.

    Stored in /Users/"username"/Library/Spelling/LocalDictionary
    Open it in TextEdit and delete the erroneous entry. Getting to the stupidly hidden Library folder is left as an exercise. I've permanently unhid it using this Terminal command:
    chflags nohidden ~/Library
    Might take a restart to take affect.

  • Remove words from Swype?

    Hello,
    Somehow I managed to get some words in Swype and I want to remove them.
    How do I remove them from my phones list of words?
    Thanks,
    VeePee
    Nokia 3395
    Nokia 6600
    Nokia N95 8GB
    Nokia N8 (Anna)
    Nokia Lumia 930
    Solved!
    Go to Solution.

    Refer this ..
    ...and Some more tips here ..

  • How to remove word from personal dictionary?

    I've searched online for this and it almost sounds like it can't be done in DW CS5, but that just seems crazy.  I added a word to my dictionary that can be spelled two ways and now, for consistency sake, want to remove one version.   Can anyone tell me if this is possible and how?
    Thank you.

    Thanks, Nancy, but that's for older versions.   According to Adobe, "Dreamweaver does not provide a way of deleting entries that have been added to personal dictionaries." 
    Maybe I'm just stubborn, but I found it hard to believe that if you accidently add a word you can never remove it.  What if you accidently clicked to add something that wasn't spelled correctly?  As I was replying to you, I poked around some more and found in C:\Users\my name\AppData\LocalLow\Adobe\Linguistics\Dictionaries\Adobe Custom Dictionary\eng (I'm running Windows 7 64 bit, so your location may vary). a file called added.clam. There is also an added.txt and exceptions.txt but there's nothing in them.
    I copied added.clam and renamed it to added.clam_Copy.txt.  Opened it up with Notepad and sure enough, my word is in there! But there are other markings in there that I don't know what they mean. I edited my word out and when I ran spell check in DW it stopped on a word that I had left in my personal dictionary.   I didn't have that many in so I went back and cleaned them all out and saved a blank added.clam.   Then when I went back to DW, ran it again, and added the words I want.
    There might be a cleaner way to fix the problem, but that worked for me.  It seems crazy that Adobe doesn't allow you to edit the dictionary but if someone using CS5 is really stuck, this will work!

  • REGEXP_REPLACE removing leading and trailing quotes.

    Hello guys,
    I have an issue with my regular expression and I'm hoping that someone can help me with it?
    Imagine the following sample_data:
    {code}
    WITH sample_data AS
    SELECT '''[email protected]''' as e FROM dual UNION ALL
    SELECT '''[email protected]' as e FROM dual UNION ALL
    SELECT '[email protected]''' as e FROM dual UNION ALL
    SELECT '''[email protected]''' as e FROM dual UNION ALL
    SELECT '[email protected]''' as e FROM dual UNION ALL
    SELECT '''[email protected]' as e FROM dual
    SELECT e, REGEXP_REPLACE(e, '(^'')?(.*)(''$)', '\2')
      FROM sample_data;
    {code}
    I would like to remove all leading and trailing quotes from the address email. I did the previous regexp but it does not returns the correct result. I don't know why, but for some reasons, when my email does not ends with a quote, the leading quote is not removed.
    Can anyone help me with this?
    Thanks,

    Cant you just trim it?
    WITH sample_data AS
    SELECT '''[email protected]'''      as e FROM dual UNION ALL
    SELECT '''[email protected]'        as e FROM dual UNION ALL
    SELECT '[email protected]'''        as e FROM dual UNION ALL
    SELECT '''[email protected]''' as e FROM dual UNION ALL
    SELECT '[email protected]'''   as e FROM dual UNION ALL
    SELECT '''[email protected]'   as e FROM dual
    SELECT e, rtrim(ltrim(e, ''''), '''') new_e
      FROM sample_data;

  • Remove word from firefox dictionary

    In the dictionary I had installed, there are misspelled words. Originally, I thought I have added them accidentally, however, after going to my profile (%APPDATA%\Mozilla\Firefox\Profiles\as6zjsxj.default) and editing persdict.dat I found out that they come from the original dictionary, not my modifications.
    I just don't understand why there's no "Remove from dictionary" context menu item.

    You can use Add to Dictionary to add you own modifications to the spell checker.
    To modify entries in the built-in or in an installed dictionary you would have to edit the used dictionary file directly on disk, either in the dictionaries folder in the Firefox program folder or in the extensions folder in the Firefox profile folder.
    *http://kb.mozillazine.org/Dictionaries
    *http://kb.mozillazine.org/Spell_checking

  • Remove word from spell_checker

    The built in deault spell-checker (OS X 10.7.2) seems to think the word "Adrain" is correctly spelled.  How can I remove this word from it's dictionary?  Note this is NOT a question about personal dictionary additions or learned words.  I do not see an "Unlearn Spelling" option for this word.  Also, I am UNIX savy so directions that involve manually editing files would be fine.

    I am running 10.6.8 and this screen shot shows where my LocalDictionary is located.
    It is Homefolder\Library\Spelling\LocalDictionary.
    Back when I was running Tiger, that file was called something else, and I used TextEdit to change it.
    I do not know if SnowLeopard works same.
    I just tested it, and I'd say that it works same, that is I edited it with TextEdit.
    Message was edited by: db24401
    Message was edited by: db24401

  • Intervative Report - Change / Remove wording on Agregates

    Hi all,
    I have an Interactive report that has, as it's main data, 12 columns (one for each month) that will always report numbers that are less than 99. I have changed the column names to be 'Jan', 'Feb', 'Mar' etc. and the report fits nicely on my page / screen.
    I then added Sum aggregation to all 12 columns, with the knowledge that the total calculated will also be less than 99. The report should therefore still fit nicley on my page / screen. However, the report shows 'Sum: 99' for each column and the 'Sum: ' element is making the columns wide enough to force the report off the side of the screen.
    Is there anyway that I can stop the report from adding the 'Sum: ' text and to just show the calculated number?
    Many thanks
    Martin

    bump

  • A function or way to identify a word before any char

    Hi All,
    I am looking for a way to identify the FIRST word BEFORE any specific character. For example :
    I have a string: "This *day*, of OCT *is*, very *Sunny*, "
    I want know if there is a function or a logic to identify just the FIRST word before ',' (here ',' is the specific character).
    So the solution would be: "day is Sunny"
    Kindly let me know.
    Thank you,
    Aj09

    Hi,
    This sounds like a job for regular expressions.
    REPLACE ( REGEXP_REPLACE ( txt
                      , '[^, ]+'     -- anything that's not a comma or space (1 or more)
                        || '( |$)'     -- right before a space (or end)
         )I assume a "word" is any group of one or more characters that does not include a comma or space.
    If other punctuation characters( like '.' and ')') delimit words, then this will have to be adjusted.
    The REGEXP_REPLACE removes all words that do not end in a comma. The comma at the end of each word kept is part of the results.
    Since you don't want the commas in the output, I used REPLACE to get rid of them.

  • Help with a ramdom word selection

    Hello everyone.
    I'm trying to write a ramdom word program using a arraylist.
    I'm NOT a student, I'm doing this as a fun project and to learn how to use ramdom method..
    code is below.
    class WordClass1 {
        private String wd_id;
        private String word_name;
        public WordClass1(String id) {
              wd_id = id;
        public WordClass1(String id, String Wd) {
             this.wd_id = id;
             this.word_name = Wd;
        // accessors
        public String getWd_id() {return wd_id;}
        public String getWord() {return word_name;}
    public String toString() {
        return "(" + wd_id  + word_name + ")";
    }//close class Person class
    public class HangmanWords {
        static ArrayList<WordClass1> arlist;
        static Scanner kbd;
        public static WordClass1 makePerson() {
            WordClass1 temp = null;
            // prompt for data
            String id;
            String Wd;
    System.out.print("Enter ID Number ==>");
    id = kbd.next();
            System.out.print("Enter Last Name ==>");
            Wd = kbd.next();
            // make an object
            temp = new WordClass1(id, Wd);
            return temp;
        public static void main(String[] args) {
             // make array list object
              List < WordClass1 > arlist = new ArrayList < WordClass1 > ();
              arlist.add(new WordClass1("A1", "STRING"));
              arlist.add(new WordClass1("A2", "PERSON"));
              arlist.add(new WordClass1("B1", "CLASS"));
              arlist.add(new WordClass1("B2", "JAVA"));
             System.out.println(arlist);
            // make a scanner
            kbd = new Scanner(System.in);
            int choice;
              System.out.println("Make a Section: ");
              System.out.println("1. Enter Word ");
              System.out.println("2. Get the word ");
              System.out.println("3. Exit this Program ");
              System.out.print("\nPlease press Enter afer each response");
              System.out.println("\nEnter your choose please: ");
              choice = kbd.nextInt();
              kbd.nextLine();
              if (choice == 1) { // if 1 is select
            }// close while loop
            if (choice == 2) { // if 2 is select go to find
                 int randomIndex = Math.abs(((Iterator<String>) arlist).next()getWord.length());
              if (choice == 3) {
                   System.out.printf("Good bye");
              }// close the choice == 3
            // print out all elements of array list
            for (WordClass1 idx : arlist) {
                 System.out.printf("Employee here are the list of all Employees Empoyeed");
                 System.out.printf("Employee Id is %s%n", idx.getWd_id());
                    System.out.printf("Name is %s  %s%n", idx.getWord());
                    System.out.println("--------------------");
            }//close for loop
    }//close main
    }//close public classmy problem lies here in which I'm trying to get the word selected.
    int randomIndex = Math.abs(((Iterator<String>) arlist).next()getWord.length());Any help would be great.
    PS this code is for a hangman game.
    nomad

    A couple of suggestions:
    1) You've got a nice WordClass1. Good to see some OOP going on. Why not do the same for HangmanWords class? Why not change the arraylist from a static variable to an instance variable? You can initialize it in the constructor. You then could create a third class: HangmanDriver that has your main. Think encapsulation.
    2) arlist I hate to say it is a terrible name for a variable. It tells you what kind of data structure the data is in, something that could easily change in the future, but doesn't tell anything about what kind of data is contained in it. It would be better to call it something else, perhaps hangmanWords or wordList or somesuch thing.
    3) try to encapsulate your user interface (I/O) routines into their own class. If you really get this program going, you're going to want to translate it from console to Swing GUI. Why not build it from the ground up in a way that would make this transition easy.
    Here's one way the HangmanWords could look:
    import java.util.ArrayList;
    import java.util.Iterator;
    import java.util.List;
    import java.util.Random;
    * encapsulates my hangman word list
    * If I make this class implement the Iterable
    * interface, I can loop through it more readily.
    * @author petes1234
    public class HangmanWords implements Iterable<WordClass1>
        private List<WordClass1> wordList;
        private Random rand;
        public HangmanWords()
            wordList = new ArrayList<WordClass1>();
            rand = new Random();
        public boolean add(WordClass1 word)
            return wordList.add(word);
        public boolean remove(WordClass1 word)
            return wordList.remove(word);
        public WordClass1 get(int i)
            return wordList.get(i);
        public WordClass1 getRandom()
            int randomIndex = rand.nextInt(wordList.size());
            return get(randomIndex);
        // this is all we need to implement the Iterable interface
        public Iterator<WordClass1> iterator()
            return wordList.iterator();
    }

Maybe you are looking for

  • Plymouth doesn't work [SOLVED]

    Hello! Plymouth doesn't work. I installed plymouth, added plymouth to HOOKS array in /etc/mkinitcpio.conf file, added "quiet splash" to /etc/default/grub file and ran "sudo grub-mkconfig -o /boot/grub/grub.cfg" followed by "sudo plymouth-set-default-

  • Streaming from laptop to hd?

    how well does streaming work from laptop to hd? i have my atv2 on backorder so i have time to decide it i want it or not. that is mostly why i want it anyway.

  • Issue ragarding creatio of excise invoices

    Dear Gurus, I am facing a strange issue when creation of excise invoice At present  Excise invoice is automatically  created at the time of saving commercial invoice , Replicating example: For 1000 deliveries system creating 1000 commercial invoices

  • Link between Personnel number, and Applicant number.

    Dear all, can anyone tell me if there's any table or infotype, wich gives me the connection between the Personnel number, and the applicant number which gave origin to that Personnel number?!? Thanks in advance. Sincerely, Hugo Ferreira

  • Problem when i create an index

    Hello, I'm a beginner on KM, and i have a simple problem (i think... ). I want to create an index on Simple Web Repository (with 2 Web Adresses created) and i have the error : " The repository needs the properties service to be attached to a classifi