Regexp

Hi,
I am working on oracle 11g. I have a question regarding regular expression. I need to get a string which is between > and % characters, some time > and % characters could be missing. Please see some examples below.
BROSSEAU<JERMAINE%KAYLA (this should not return any thing as there is no > charecter)
CLARKE<CATHERINE~ (this should not return any thing as there is no > and % charecter)
GARCIA REBOLLEDO<LUZ%ELENA~ (this should not return any thing as there is no > charecter)
SYKES JR.<THOMAS>L (this should not return any thing as there is no % charecter)
SALVIDRES<SANDY>J%YGNACIO (this should return J )
Similarly for the below i need values between % and ~ or % and null
BROSSEAU<JERMAINE%KAYLA (this should return KAYLA)
CLARKE<CATHERINE~ (this should not return any thing as there is no % charecter)
GARCIA REBOLLEDO<LUZ%ELENA~ (this should return ELENA)
SYKES JR.<THOMAS>L (this should not return any thing as there is no % charecter)
SALVIDRES<SANDY>J%YGNACIO (this should return YGNACIO)
Appreciate your help with this.
Thanks,
Jacky

Hi, Jacky,
user11290011 wrote:
I am working on oracle 11g...Good! This was harder in Oracle 10.
I have a question regarding regular expression. I need to get a string which is between > and % characters, some time > and % characters could be missing...Here's one way:
SELECT     REGEXP_SUBSTR ( str
                , '>([^%]*)%'
                , 1
                , 1
                , NULL
                , 1
                )          AS sub_str
FROM    table_x
Similarly for the below i need values between % and ~ or % and null
SELECT     REGEXP_SUBSTR ( str
                , '%([^~]*)'
                , 1
                , 1
                , NULL
                , 1
                )          AS sub_str
FROM    table_x
;

Similar Messages

  • Search and Replace String throwing the wrong error message with regexp?

    This came up in a LAVA thread, and I'm not sure if there's a bug here or not. When using Search and Replace string, and using a regular expression of [(G[b|i])], LabVIEW throws error -4622, "There is an unmatched parenthesis in a regular expression."  There are obviously no unmatched parenthesis in that expression, so it seems to me that the wrong error is being thrown. I'm just not sure if that's a syntactically valid regexp. The problem seems to be with nesting [ ]'s inside ( )'s inside [ ]'s. I've tried a couple of regexp resources on the Web, and one suggests it's valid, while the other seems to think it isn't.
    Message Edited by eaolson on 03-13-2007 10:33 AM
    Attachments:
    ATML_StandardUnit2.vi ‏10 KB
    regexp.png ‏5 KB

    adambrewster wrote:
    I think your regexp is invalid.
    In regexps, brackets are not the same as parentheses.  Parens are for grouping, while brackets are for matching one of a class of characters.  Brackets can not be nested.
    If the regexp is replaced with [G[bi]], there is no error, so it's not a matter of nested brackets. I couldn't find anything on the PCRE man page that forbids nested brackets specifically, but it makes sense.
    Your expression "[(G[bi])]", therefore parses as a character class which matches '(', 'G', '[', 'b', or 'i' followed by an unmatched paren, and an unmatched bracket.
    I don't believe that's the case. Replace the regexp with [(Gbi)], and the error goes away. So it's not a matter of the '(' being literal, and then encountering a ')' without a matching '('.
    daveTW wrote:
    what string exactly you want to replace? I think the round braces are not right in this case, since they mark partial matches which are given back by "match regular expression". But you don't want to extract parts of the string, you want to replace them (or delete, with empty <replace string>). So if you leave the outer [( ... )] then your RegEx means all strings with either "Gb" or "Gi".
    It's not my regular expression. A poster at LAVA was having problems with one of his (a truly frightening one), and this seemed to be the element that was causing the problem. I'm pretty sure that the originator of the regexp meant to use G(b|i), which seems like a complicated way of matching "Gb" or "Gi", if you ask me.

  • RegExp not working like it should

    Maybe I just need another pair of eyes looking at this, but I have a RegExp instance that should work according to multiple tools on the web but it's not matching when it should in my application.  The expression should match if there isn't any leading or trailing spaces.  Here's a code snippet:
    var regexp:RegExp = new RegExp("^\S.*\S$|^\S(?!.)", "s");
    if(regexp.exec("Hello World") == null)
         trace("NO MATCH");
    Using tools such as Grant Skinners RegExr (http://gskinner.com/RegExr/) it appears that the previous code should get a match.  Does anyone see an issue or know why it isn't working?

    Hi All,
    while assigning value to a RegEx in constructor itself, we can either specify pattern (for which we need not  escape already escaped character)
    like
    var regexp:RegExp = new RegExp(/^\S.*\S$|^\S(?!.)/s)
    or we can specify a string (for which we need to escape already escaped characters)
    like
    var regexp:RegExp = new RegExp("^\\S.*\\S$|^\S(?!.)","s")
    Regards,
    Abihshek Chaudhary

  • Is this a RegExp bug??? Matching double letters inside words...

    I'm trying to match double letters inside words, excluding ones that begin or end a word.  I'm running into a problem matching \B at the end of a line.
    example:
    My RegExp is /\Bdd\B/gi
    String is "dda adda add add"
    This will match twice, the dd in the 2nd word, and the dd in the 4th word.  Why is it matching the 4th word??

    It matches only once. Make sure there are no other characters in the end of your string.

  • [JS CS3] RegExp Object containing only one backslash (how to escape)

    Hi
    I'm trying to escape one backslash in my RegExp Object, but I get a Syntax Error:
         myObj = new RegExp ( "\\" );
    I tried it phyton Style   myObj = new RegExp ( "\\\\" ); but that's not working right.
    Thanks for any hint.
    Stefan

    Stefan,
    First of all, in your sample text you need to escape your backslash as well:
    myText = "This is an \\ of search and replace.";
    You can see this in these examples:
    alert ("a\rb") prints "a" then "b" on a new line; alert ("a\\rb") prints "a\rb".
    Another problem is that you use a regex as the replacement object (myWhit), but that should be a string. With these two things corrected, it works fine:
    function main()
         var myText = "This is an \\ of search and replace.";
         var myWhat = new RegExp ( "\\\\" );
         var myWhatSearch = new RegExp ( "\\\\" );
         var myWhit = "example";
         alert( myReplaceExample( myText, myWhatSearch, myWhat, myWhit) );
         return true;
    That new RegExp ("\\") can't be correct can be seen if you start with a literal regex, in which you would use an escaped backslash:
    myText = myText.replace (/\\/, "example")
    To use \\ in a new RegExp () construction, you need to place it in a string, and you need to escape both backslashes, so you end up with "\\\\".
    Peter

  • RegExp for excluding special characters in a string.

    Hi All,
    Im using Flex RegExpValidator. Can anyone suggest me the correct expression to validate this condition?....
    I have tried this expression :----- /^[^///\/</>/?/*&]+$/...But in this it is also negating the alphabets.Also I have tried with opposite condition that in the String we should have alphabets and the expression is:-- ([a-z]|[A-Z]|[0-9]|[ ]|[-]|[_])*..... Please can anyone help me on this.
    Thanks in advanced to all.
    Munira

    sorry but you are posting things back that do not make any sense
    what do you mean with the below comment?
    munira06 wrote:
    Yes you are correct ,but I have tried this with single special character
    say
    Re: RegExp for excluding special characters in a string.
    here is a sample app taken from the live docs
    using ^[a-zA-Z0-9 \-_]*$ as the regex accepts all characters from a-z, A-Z, 0-9 - [space] and_
    run the example tell me what regex you are using and what test strings fail when they should pass or pass when they should fail
    <?xml version="1.0" encoding="utf-8"?>
    <!-- Simple example to demonstrate the RegExpValidator. -->
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
            xmlns:s="library://ns.adobe.com/flex/spark"
            xmlns:mx="library://ns.adobe.com/flex/mx">
        <fx:Script>
            <![CDATA[
                import mx.events.ValidationResultEvent;
                import mx.validators.*;
                // Write the results to the
                private function handleResult(eventObj:ValidationResultEvent):void {
                    if (eventObj.type == ValidationResultEvent.VALID) {
                        // For valid events, the results Array contains
                        // RegExpValidationResult objects.
                        var xResult:RegExpValidationResult;
                        reResults.text = "";
                        for (var i:uint = 0; i < eventObj.results.length; i++) {
                            xResult = eventObj.results[i];
                            reResults.text=reResults.text + xResult.matchedIndex + " " + xResult.matchedString + "\n";
                    } else {
                        reResults.text = "";
            ]]>
        </fx:Script>
        <fx:Declarations>
            <mx:RegExpValidator id="regExpV"
                    source="{regex_text}" property="text"
                    flags="g" expression="{regex.text}"
                    valid="handleResult(event)"
                    invalid="handleResult(event)"
                    trigger="{myButton}"
                    triggerEvent="click"/>
        </fx:Declarations>
        <s:Panel title="RegExpValidator Example"
                width="75%" height="75%"
                horizontalCenter="0" verticalCenter="0">
            <s:VGroup left="10" right="10" top="10" bottom="10">
                <s:Label width="100%" text="Instructions:"/>
                <s:Label width="100%" text="1. Enter text to search. By default, enter  a string containing the letters ABC in sequence followed by any digit."/>
                <s:Label width="100%" text="2. Enter the regular expression. By default, enter ABC\d."/>
                <s:Label width="100%" text="3. Click the Button control to trigger the validation."/>
                <s:Label width="100%" text="4. The results show the index in the text where the matching pattern begins, and the matching pattern. "/>
                <mx:Form>
                    <mx:FormItem label="Enter text:">
                        <s:TextInput id="regex_text" text="xxxxABC4xxx" width="100%"/>
                    </mx:FormItem>
                    <mx:FormItem label="Enter regular expression:">
                        <s:TextInput id="regex" text="ABC\d" width="100%"/>
                    </mx:FormItem>
                    <mx:FormItem label="Results:">
                        <s:TextInput id="reResults" width="100%"/>
                    </mx:FormItem>
                    <mx:FormItem >
                        <s:Button id="myButton" label="Validate"/>
                    </mx:FormItem>
                </mx:Form>
            </s:VGroup>
        </s:Panel>
    </s:Application>

  • JS RegExp Bug in CS5

    var text = "aXbY";
    var re = /^(.*?)(?:X(.+)Y)?$/;
    alert(text.match(re));
    Returns "aXbY,,b" in Photoshop instead of "aXbY,a,b".
    The non-capturing parentheses seems to be the problem.

    This:
    var reg = RegExp("^(\+|\-)?(\d|\.\d|\d\.\d)$");
    should be this:
    var reg = RegExp("^(\\+|\\-)?(\\d|\\.\\d|\\d\\.\\d)$");
    if what you want is really this:
    var reg = /^(\+|\-)?(\d|\.\d|d\.\d)$/;
    The mappings between String literals and RegExp literals can be dicey, especially if the strings are getting constructed at runtime. The syntax error in the first case are probably from the + and - not being fully escaped when parsed by the RegExp constructor.
    -X

  • RegExp bug in CS5

    This appears to send the RegExp engine into an infinite loop in PSCS5 but behaves fine in CS4.
    "-".match(/^(\+|\-)?(\d+|\.\d+|\d+\.\d+)$/)
    Can somebody verify this for me?

    This:
    var reg = RegExp("^(\+|\-)?(\d|\.\d|\d\.\d)$");
    should be this:
    var reg = RegExp("^(\\+|\\-)?(\\d|\\.\\d|\\d\\.\\d)$");
    if what you want is really this:
    var reg = /^(\+|\-)?(\d|\.\d|d\.\d)$/;
    The mappings between String literals and RegExp literals can be dicey, especially if the strings are getting constructed at runtime. The syntax error in the first case are probably from the + and - not being fully escaped when parsed by the RegExp constructor.
    -X

  • Find and print illegal character in a string using regexp

    I have the following simple regexp that checks for illegal characters in a string:
    String regexp = ".*([\\[\\];]+|@).*"; // illegal: [ ] ; @
    String input = "Testing [ 123";
    System.out.println(Pattern.matches(regexp, input));How can I find and print the character that is invalid??
    I've tried using the Matcher class togheter with Pattern but cant get it to work. :(
    Like this:
    Pattern pattern = Pattern.compile(regexp);
    Matcher matcher = pattern.matcher(input);
    matcher.lookingAt();
    int matchedChar = matcher.end();
    if (matchedChar < input.length()) {
        String illegalCharFound = String.valueOf(input.charAt(matcher.end()));
        System.out.println(illegalCharFound);
    }What am I doing wrong?

    1. You call lookingAt(), but you don't check its return value, so you don't know if the regex actually matched.
    2. matcher.end() returns the index of the character following whatever was matched, assuming there was a match (if there wasn't, it will throw an exception). So either it will point to a legal character, or you'll get a StringIndexOutOfBoundsException because an illegal character was found at the end of the input. The start() method would be a better choice, but...
    3. Your regex can match multiple consecutive square brackets or semicolons (and why not put the at-sign in the character class, too?), but you're acting like it can only match one character. Even if there is only one character, group(1) is an easier way to extract it. Also, if there are more than one (non-consecutive) illegal characters, your regex will only find the last one. That's because the first dot-star initially gobbles up the whole input, then backtracks only as far as it has to to satisfy the rest of the regex. If your goal is to provide feedback to whoever supplied the input, it's going to be pretty confusing feedback. You should probably use the find() method in a loop to pick out all the illegal characters so you can report them properly.

  • Bug report: SQL Developer 3.2.09 Crashes for some Replace Regexp

    Hi,
    SQL Developer 3.2.09 (tested on Win XP with SQL Developer built-in Java) crashes for some Replace Regexp.
    Try the following:
    New SQL-sheet
    CTRL-R for Replace
    Enter "||" (two chars) as search-expression
    Enter "" (nothing) as replace-with-expression
    Check Regular Expressions Check Box
    Hit OK
    -->100% CPU usage, no reaction.
    Can you confirm the bug?
    Edited by: blama on Sep 4, 2012 3:48 PM

    I believe the pipe character is a regexp meta character and your regexp probaby matches everything repeatedly. If you want to replace the concatenation operator you don't need a regexp.
    Having said that, I am using SQL Developer on Linux with Java 1.6.0_33 and I don't get the hang, just replacing the same thing again and again.
    On windows with 1.6.0_24, I do get the hang. It may be a java issue.
    Edited by: Jim Smith on Sep 4, 2012 5:39 PM

  • How can I reference a variable in Regexp

    Hello Friends,
    I have this Regexp, to extract the county code: (971)
    select regexp_replace (regexp_replace('000971-05 7910 - 324324','\D'),'^0*(971)?0?') from dual;It is fine and does the need..
    But, thinking in the future, someone may need to eliminate the country code of (961), so it is better if I put the code in a variable, but
    How can I reference the county code using a variable in Regexp:
    declare
    a varchar2 (15);
    code number := 971;
    begin
    select regexp_replace(regexp_replace('000971 05 7910 - 324324','\D'),'^0*(code)?0?') into a from dual;
    dbms_output.put_line ( a);
    end;but, it does not work ??
    Best Regards,
    Fateh

    venx08 wrote:
    You need to bind the code variable value in the regular expression patternYes, that's the idea, but there is a caveat. You might need to escape every regexp special character that appears in code. If, for example code is 'A*B' you need to transform it into 'A\*B' unless you really want 'A*B' to be interpreted as uppercase A repeated zero or more times followed by uppercase B.
    SY.

  • REGEXP and BLOB

    Hi
    One of my BLOB column contains a text which I need to check in my SQL Query.
    Can we achive this by using REGEXP?
    Is there is any other way to determine the value of fields/data inside BLOB in SQL Query (Not in Procedure or Function)?
    Kapilk

    You mean CLOB ? BLOB is binary type you can't get reasonable text out of it.
    Yes, Regular Expressions works with CLOB
    http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14251/adfns_regexp.htm#sthref534
    Oracle Database Implementation of Regular Expressions
    Oracle Database implements regular expression support with a set of Oracle Database SQL functions and conditions that enable you to search and manipulate string data. You can use these functions in any environment that supports Oracle Database SQL. You can use these functions on a text literal, bind variable, or any column that holds character data such as CHAR, NCHAR, CLOB, NCLOB, NVARCHAR2, and VARCHAR2 (but not LONG).

  • How to use REGEXP for case statement

    Hello everyone, I'm very new here and am struggling with a using REGEXP in a case statement, OK I am using the REGEXP to find all strings that match a specific format for a particular brand of product, for example serial numbers, and I need to be able to say something like [case when(xx.brandid) = '123' then if xx.serialnumber REGEXP_LIKE(xx.serialnumber,'[A-za-z][A-za-z][A-za-z]\d{5,}[A-za-z]$') then 'TRUE' else 'FALSE' end "TRUE/FALSE".]
    Help would be greatly appreciated with this as I feel like I'm going backwards trying to figure this out
    Thanks in advance for any assistance.

    Like this?
    case
       when xx.brandid = '123' and
            regexp_like(xx.serialnumber,'[A-za-z][A-za-z][A-za-z]\d{5,}[A-za-z]$') then
          'TRUE'
       else
          'FALSE'
    end

  • Regexp in sql query

    Hai all,
    i want to get value from decimal column as tow columns using "regexp" in sql query
    that means 72.58 value
    as 72 value1 , 58 value2
    need help.........

    Hi Hari,
    Made a format change in query using decode.
    SQL> with t
      2  as
      3  (
      4  select '12.58' str from dual union all
      5  select '.72' str from dual
      6  )
      7  select regexp_substr(decode(substr(str,1,1),'.',lpad(str,length(str)+1,'0'),
      8                              str),'[^.]+',1,1) val1,
      9  regexp_substr(decode(substr(str,1,1),'.',lpad(str,length(str)+1,'0'),
    10                              str),'[^.]+',1,2) val2
    11  from t
    12  /
    VAL1       VAL2
    12         58
    0          72

  • Where should i place the akarta-regexp-1.3.jar

    I'm coding on linux for jakarta-tomcat server..
    I'download jakarta-regexp-1.3.jar file from jakarta-apach site for validate a email adress..
    But i did not find any doc to telle me where put this file..
    I put it in the jre subdirectory of my sdk directory but the javac compiler
    do not recognize this part of my code import org.apache.regexp.* ..I try the lib directory of the tomcat and it was same..
    Where should i put this jar file ..
    Could some body help me ?

    DON'T CROSS POST, EEJIT:
    http://forum.java.sun.com/thread.jsp?thread=461653&forum=33&message=2116135
    http://forum.java.sun.com/thread.jsp?thread=461654&forum=45&message=2115945
    http://forum.java.sun.com/thread.jsp?thread=461653&forum=33&message=2115943
    http://forum.java.sun.com/thread.jsp?thread=461652&forum=1&message=2115941

  • Quick question about RegExp

    Just a quick question.
    In other languages, I can do this...
    while(reg.exec(string)) {
         //loop through results
    And while looping, I can access the current match with something like reg.Match or whatever. 
    Is this possible in AS?

    Look up the RegExp class.

Maybe you are looking for

  • Work item not getting displayed in the portal

    Hi  experts, We are creating a protoype for one of the standard HCM form for change in working time. When we initiate the process, the workflow is supposed to identify the agent(which is the manager in this case) and push the work item in the inbox o

  • I updated iTunes and now my 160 GB iPod Classic makes iTunes freeze.

    I have done everything from resetting the iPod to uninstalling and reinstalling iTunes.  I have formatted and reformatted the iPod.  The iPod actually works, I can go through and fix the settings to my liking.  But when I go to sync with my iTunes, i

  • How do I install Reader to a PC that is not internet connected?

    I have a PC that is not connected to the internet.  How can I install Adobe Reader on it, as a normal installation goes directly from adobe.com to the PC.  I could download the software to a memory stick but there does not seem to be a single file av

  • Burning to Full-screen

    In v.11, how do  I get the program to burn the DVD to full-screen?  I have told it to do so, but I keeps on burning to widescreen.

  • Which logic board do I need?

    I need to buy a replacement logic board for a PowerBook G4 15"...what are the specs for which one I should buy? My laptop's Model Number is UJ-825-C and Serial Number is W84424JFQHY. Know where I can get a cheap logic board?