Regular expression matches string starts with &

Hello,
I am trying to write a Reg Exp that removes any string starts with "&" and Ends with ";" . In other words, I am trying to remove anything similar to:
& nbsp;  & quot; & lt; & gt;  Any help please.
This does not work:
select regexp_replace(ename, '^&[a-z]{2,4}[;]$') from emp;Regards,
Fateh

Fateh wrote:
I am trying to write a Reg Exp that removes any string starts with "&" and Ends with ";" . In other words, I am trying to remove anything similar to:
& nbsp;  & quot; & lt; & gt; 
Those are entity references (without the whitespace after '&').
Do you really want to remove them, or do you actually want to convert them back to their corresponding characters but don't know how to do it?
SQL> set scan off
SQL> select utl_i18n.unescape_reference('"Test": 3>2') from dual;
UTL_I18N.UNESCAPE_REFERENCE('&
"Test": 3>2

Similar Messages

  • Regular Expressions and String variables

    Hi,
    I am attempting to implement a system for searching text files for regular expression matches (similar to something like TextPad, etc.).
    Looking at the regular expression API, it appears that you can only match using string variables. I just wanted to make sure this is true. Some of these files might be large and I feel uneasy about loading them into ginormous Strings. Is this the only way to do it? Can I make a String as big as I want?
    Thanks,
    -Mike

    Newlines are only a problem if you're reading the
    text line-by-line and applying the regexp to each
    line. It wouldn't catch expressions that span
    lines.
    @sabre150: your note re: CharSequence -- so what
    you're suggesting is to implement a CharSequence that
    wraps the file contents, and then use the regexps on
    the whole thing? I like the idea but it seems like
    it would only be easy to implement if the file uses a
    fixed-width character set. Or am I missing
    something...?You are correct for the most basic implementation. It is very easy to create a char sequence for fixed width character sets using RandomAccessFile. Once you go to character sets such as UTF-8 then more effort is required.
    While ever the regex is moving forward thought the CharSequence one char at a time there is no problem because one can wrap a Reader but once it backtracks then one needs random access and one will need to have a buffer. I have used a ring buffer for this which seems to work OK but of course this will not allow the regex to move to any point in the CharSequence.
    'uncle_alice' is the regex king round here so listen to him.
    :-( I should read further ahead next time!
    Message was edited by:
    sabre150
    Message was edited by:
    sabre150

  • Wat should be the regular expression for string MT940_UB_*.txt to be used in SFTP sender channel in PI 7.31 ??

    Hi All,
    What should be the regular expression for string MT940_UB_*.txt and MT940_MB_*.txt to be used as filename inSFTP sender channel in PI 7.31 ??
    If any one has any idea on this please let me know.
    Thanks
    Neha

    Hi All,
    None of the file names suggested is working.
    I have tried using - MT940_MB_*\.txt , MT940_MB_*.*txt , MT940*.txt
    None of them is able to pick this filename - MT940_MB_20142204060823_1.txt
    Currently I am using generic regular expression which picks all .txt files. - ([^\s]+(\.(txt))$)
    Let me know ur suggestion on this.
    Thanks
    Neha Verma

  • How to test if String starts with a Range of numbers

    Hello,
    I'm reading in a line from a text file and I want to see if that line starts with numbers.
    I know there is
    String temp = file.readline();
    if (String temp.startsWith(?1-9?); // want to check if string starts with 1 thru 9
    Thanks!

    Try the following:
    String temp = file.readline();
    if (temp.equals("1") || temp.equals("2")....... || temp.equals("9") {
    System.out.println("String is beetween 1 - 9");
    else{
    System.out.println("String is not beetween 1 - 9");
    Replace the "....." by the other values... I know it's quite long, but it should work... must be an easier way though...
    Pierre

  • Regular Expressions and String

    How do I return a String array as follow using regular expression.
    String[] strArray = {"Now is the time", "you can optionally preview your post","message by using a number of special tokens."}
    from this string
    <separator>Now is the time</separator><separator>you can optionally preview your post</separator><separator>message by using a number of special tokens.</separator>
    Note: The string has the <separator> XML tag

    How do I return a String array as follow using regular
    expression.
    String[] strArray = {"Now is the time", "you can
    optionally preview your post","message by using a
    number of special tokens."}
    from this string
    <separator>Now is the time</separator><separator>you
    can optionally preview your
    post</separator><separator>message by using a number
    of special tokens.</separator>
    Note: The string has the <separator> XML tag
    This cannot be done using simple regular expressions - at least not if your number of <separator>s is random, which is what you seem to imply.
    Simple regular expressions are one-off, that means it can have a String array as a result, but only to the amount of brackets in the regex.
    a regex like:
    <separator>([^<]*)</separator><separator>([^<]*)</separator><separator>([^<]*)</separator>
    would return what you want, but I doubt that it is as flexible as you want it to be.

  • String "starts with" function in ABAP

    Hi!
    I need to check in ABAP, if a given profit center (char 10) starts with P172. It could be filled with zeros -> 0000P17255. So I need to perform 2 actions:
    1)
    Lefttrim the 0 -> Result: P17255.
    2)
    Check, if the string starts with P172.
    How can I do this in ABAP?
    Thanks,
    Konrad

    Hi,
    You can do as below :
    1st scenario :
    loop at itab.
    "Below code will delete leading zero.
    SHIFT itab-prctr LEFT DELETING LEADING '0'.
    "Second scenario
    if itab-prctr(4) = 'P1972'.
    "Do necessary coding as per your requirment.
    endif.
    "If you wnat chnage tje contensts of the itab you can use modify else you append to append to another internal table.
    endloop.
    Thanks,
    Sriram POnna

  • Regular expressions and string matching

    Hi everyone,
    Here is my problem, I have a partially decrypted piece string which would appear something like.
    Partially deycrpted:     the?anage??esideshe?e
    Plain text:          themanagerresideshere
    So you can see that there are a few letter missing from the decryped text. What I am trying to do it insert spaces into the string so that I get:
                        The ?anage? ?esides he?e
    I have a method which splits up the string in substrings of varying lengths and then compares the substring with a word from a dictionary (implemented as an arraylist) and then inserts a space.
    The problem is that my function does not find the words in the dictionary because my string is only partially decryped.
         Eg:     ?anage? is not stored in the dictionary, but the word �manager� is.
    So my question is, is there a way to build a regular expression which would match the partially decrypted text with a word from a dictionary (ie - ?anage? is recognised and �manager� from the dictionary).

    I wrote the following method in order to test the matching using . in my regular expression.
    public void getWords(int y)
    int x = 0;
    for(y=y; y < buff.length(); y++){
    String strToCompare = buff.substring(x,y); //where buff holds the partially decrypted text
    x++;
    Pattern p = Pattern.compile(strToCompare);
    for(int z = 0; z < dict.size(); z++){
    String str = (String) dict.get(z); //where dict hold all the words in the dictionary
    Matcher m = p.matcher(str);
    if(m.matches()){
    System.out.println(str);
    System.out.println(strToCompare);
    // System.out.println(buff);
    If I run the method where my parameter = 12, I am given the following output.
    aestheticism
    aestheti.is.
    demographics
    de.o.ra.....
    Which suggests that the method is working correctly.
    However, after running for a short time, the method cuts and gives me the error:
    PatternSyntaxException:
    Null(in java.util.regex.Pattern).
    Does anyone know why this would occur?

  • Match Regular Expression won't work with Null

    Is that right? I don't see it in the documentation. I can use it on \01 , just not \00.
    Is there a way around this problem? I know that Match Pattern works, but I want to use it with separate partial matches (a|b) which Match Pattern does not support.

    Here's a possibility:
    If you try to set the constant "\00" to "\0" with the '\' Code Display on, it just converts it back to "\00" on the display.
    The function uses the PCRE library.  From the library documentation (the pcrepattern man page):
    "After \0 up to two further octal digits are read. In both cases, if there
    are fewer than two digits, just those that are present are used. Thus the
    sequence \0\x\07 specifies two binary zeros followed by a BEL character
    (code value 7). Make sure you supply two digits after the initial zero if the
    pattern character that follows is itself an octal digit."
    So, what if, behind the scenes, LV is actually feeding the match function just a "\0"?  I'm guessing (but haven't been able to verify) it would match *any* input string, immediately, with an offset of zero.  Testing with random search strings shows behavior that might indicate this.
    If the above is true, getting around it might be hard, since you're at the mercy of LV as to exactly how it calls that library.
    Fun stuff... okay, back to work with me.  Good luck,
    Joe Z.

  • Regular expressions for replacing text with sms language text

    Hi, I'm trying to write a function which converts normal, correctly spelled text into the shorter sms language format but struggling to come up with the regular expressions i need to do so, can anyone help?
    1: remove surplus white space at the beginning of a sentence and at the end of a sentence.
    e.g. " hello." --> "hello." OR "hello ." --> "hello."
    2: remove preceeding and/or proceeding space if there's a word then a number possibly followed by another word
    e.g. "come 2 me" --> "come2me" OR "dnt 4get" --> "dnt4get"
    3: remove "aeiou" if word starts and ends with "!aeiou"
    e.g. "text" --> "txt"

    You can make the whitespace on either side optional:   text = text.replaceAll("\\s*(\\d)\\s*", "$1");1. Use String's trim() method.
    3. This one has to be done in two steps: import java.util.regex.*;
    public class Test
      public static void main(String... args) throws Exception
        String text = "The quick brown fox jumps over the lazy dog.";
        System.out.println(devowelize(text));
      public static String devowelize(String str)
        Pattern p = Pattern.compile(
          "[a-z&&[^aeiou]]++(?:[aeiou]++[a-z&&[^aeiou]]++)+",
          Pattern.CASE_INSENSITIVE);
        Matcher m = p.matcher(str);
        StringBuffer sb = new StringBuffer();
        while (m.find())
          m.appendReplacement(sb, m.group().replaceAll("[aeiou]+", ""));
        m.appendTail(sb);
        return sb.toString();
    }

  • Get all groups from a regular expression match

    Please help me understand how to use Java regular expressions:
    I have an expression similar to this:
    {noformat}"([^X]+)(X[^X]*)+"{noformat}This should match stuff like "asaasaXdfdfdfXXsdsfd".
    How does one access all the matches for the second group (the second groups has a Kleene operator
    added so it is not really just one group --- but match.groupCount() is always 2)
    Here is roughly the code:
    {noformat}java.util.regex.Pattern pattern = {noformat}{noformat}java.util.regex.Pattern.compile({noformat}{noformat}"([^X]+)(X[^X]*)+",{noformat}{noformat}java.util.regex.Pattern.MULTILINE{noformat}{noformat});{noformat}{noformat}java.util.regex.Matcher matcher = pattern.matcher(text);{noformat}{noformat}matcher.find();{noformat}{noformat}int groupcount = matcher.groupCount();{noformat}
    Also, without matcher.find() I get an illegalStateException .. which I also get if I use matcher.matches() instead
    of matcher.find().
    I am obviously missing something here. There is always at least one "X" in the string so shouldn't that pattern always
    match the whole string? Since there are often multiple X, shouldnt I get a group for each occurrence of X, followed
    by 0 or more other characters?
    {noformat}But when I try to match everything by using "^([^X]+)(X[^X]*)+$" I get an "IllegalStateException: No match available" again.{noformat}
    What is the correct way to do this?
    Edited by: johann_p on May 16, 2008 10:39 AM

    I am sorry I messed this up. Here is a SSCCE:
    import java.util.regex.Pattern;
    import java.util.regex.Matcher;
    class RegExp1 {
        public static void main(String[] args) {
          String testString = "first|aaaa | bbbb\n|cccc|ddddd";
          Pattern pattern = Pattern.compile("^([^|]+)(\\|[^|]*)+$");
          Matcher matcher = pattern.matcher(testString);
          matcher.find();
          int groupcount = matcher.groupCount();
          System.out.println("Found "+groupcount+" groups");
          System.out.println("Matcher: "+matcher);
          for (int i = 1; i <= groupcount; i++) {
            System.out.println("Match "+i+": "+testString.substring(matcher.start(i),matcher.end(i)));
    }I figured out a small bug in my first code that explains some of the exception oddities, but my principal question remains:
    how do I access all the matches that correspond to the second capturing group?
    In the example I would get "first" for Match 1 and "|ddddd" for Match 2, but how do I access all the matches??
    Thank you for your help!

  • Extracting a  a piece of string starting with a number

    Hi,
    I am new to SQL, so I could use some help with the following issue. I need to extract contract number from a string, but the position of the contract number and the text inside of the string might vary, which means it is important to tie the SELECT statement to the number. Extracting only numbers wouldn't help too, because contract number contains letters and other characters. For example, if there was a string "Payment to a contract nr 1100/70HE", the SELECT statement should be able to extract only "1100/70HE" from that string.
    Thank you in advance,
    Keit

    Hi,
    welcome to the forum.
    Please read SQL and PL/SQL FAQ
    When you put some code or output please enclose it between two lines starting with {noformat}{noformat}
    i.e.:
    {noformat}{noformat}
    SELECT ...
    {noformat}{noformat}
    Coming to your question, I would say that extracting the contract number from a string it is not the ideal solution for a data model.
    Beside that, you may be able to reach your goal by using regular expression but you should provide more example and explain if the contract number could be identified with a specific pattern.
    I suggest you to post some sample data (CREATE TABLE and INSERT statement or a WITH statement) and try to identify a rule that can apply to extract your data.
    I.e.: if contract number always is one or more characters, followed by a slash (/) and followed by one or more characters then maybe you can use regular expression to identify it. I suggest you to post some cases and try to find the logic to apply.
    Regards.
    Al                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Regular Expression Fails String replaceAll

    I am trying to use regular expressions to replace double backslashes in a string with a single backslash character. I am using version 1.4.2 SDK. Upon invoking the replaceAll method I get a stack trace. Does this look like a bug to anyone?
    String s = "text\\\\";  //this results in a string value of 'text\\'
    String regex = "\\\\{2}";  //this will match 2 backslash characters
    String backslash = "\\";
    s.replaceAll(regex,backslash); java.lang.StringIndexOutOfBoundsException: String index out of range: 1
         at java.lang.String.charAt(String.java:444)
         at java.util.regex.Matcher.appendReplacement(Matcher.java:551)
         at java.util.regex.Matcher.replaceAll(Matcher.java:661)
         at java.lang.String.replaceAll(String.java:1663)
         at com.msdw.fid.fitradelinx.am.client.CommandReader.read(CommandReader.java:55)
         at com.msdw.fid.fitradelinx.am.client.CommandReader.main(CommandReader.java:81)
    Exception in thread "main"

    Skinning the cat -
    public class Fred12
        public static void main(String[] args)
                String s = "text\\\\";  //this results in a string value of 'text\\'
                String regex = "[\\\\]{2}";  //this will match 2 backslash characters
                String backslash = "\\\\";
                System.out.println(s.replaceAll(regex,backslash));
                String s = "text\\\\";  //this results in a string value of 'text\\'
                String regex = "(\\\\){2}";  //this will match 2 backslash characters
                String backslash = "\\\\";
                System.out.println(s.replaceAll(regex,backslash));
                String s = "text\\\\";  //this results in a string value of 'text\\'
                String regex = "(?:\\\\){2}";  //this will match 2 backslash characters
                String backslash = "\\\\";
                System.out.println(s.replaceAll(regex,backslash));
                String s = "text\\\\";  //this results in a string value of 'text\\'
                String regex = "(?:\\\\)+";  //this will match 2 or more backslash characters
                String backslash = "\\\\";
                System.out.println(s.replaceAll(regex,backslash));
                String s = "text\\\\";  //this results in a string value of 'text\\'
                String regex = "\\\\\\\\";  //this will match 2 backslash characters
                String backslash = "\\\\";
                System.out.println(s.replaceAll(regex,backslash));
    }

  • Regular Expressions - matching a brace

    I am a bit of a begginner when it comes to regular expressions - but I am trying to replace all curly braces - {} in a string with normal brackets - ().
    This is how I'm trying to do it -
    //replace any curly braces with normal brackets
    Pattern p = Pattern.compile("{");
    Matcher m = p.matcher(value);
    value = m.replaceAll("(");
    However, I get an exception when my code is run: "java.util.regex.PatternSyntaxException: Illegal repetition {"
    Any idea how to replace a brace character? Also, is there an easy way to replace both the open brace - { and close brace - } characters in one expression?
    Regards,
    Jake

    ..Also, is there an easy way to replace both the open brace - {
    and close brace - } characters in one expression?
      // only for paired curly braces
      while (target.matches(".*\\{(.*)\\}.*")) {
        target = target.replaceAll("\\{(.*)\\}", "($1)");

  • Regular expression: Split String

    Hi everybody,
    I got to split a string when <b>'</b> occurs. But the string should <u>not</u> be splitted, when a <b>?</b> is leading the <b>'</b>. Means: Not split when <b>?'</b>
    How has the regular expression to look like?
    This does NOT work:
    String constHOCHKOMMA = "[^?']'";
    <u>Sample-String:</u>
    String edi = "UNA'UNB'UNH?'xyz";
    Result should be
    UNA
    UNB
    UNH?'xyz
    Thanks regards
    Mario

    Hi
    I think u can meke it in two ways
    1. using split function u r giving single quote as your delimiter, after each split funcction just add one more split function with delimiter as ?, if it returns true add the previous splited string and next one
    2.  you are gooing through each and every char  of your string  and split when next single quote occur, for this u are comparing each of your char with ['] i believe,
    just compare the char with '?' if it match ignore next single quote.
    Regards
    Abhijith YS

  • Regular Expressions on strings

    How would I go about creating a regular expression in LabVIEW that, say, takes an input of a list of numbers (1, 2, 3, 4, 5) and turns it into an array with the elements [1, 2, 3, 4, 5]? If someone could show me example code, I would be quite grateful.
    Thanks.
    Using LabVIEW 2009 on Windows Vista

    Spreadsheet String to Array should work for conversion to strings or numbers...
    Richard
    Attachments:
    stringarr.gif ‏18 KB

Maybe you are looking for