Regular expression to get substring from string

Hi,
I’m having the following problem:
SELECT REGEXP_SUBSTR(';first field;ir-second field-02;ir-second field-01; third field','.*ir-(.*)-01.*’)FROM dual
[\CODE]
This is the select that I have with a java expression!
In java I’m able to do find the right expression to retrieve what I want, but I don’t know how to adapt this for oracle!
  In oracle I was trying to do something like this:
NVL(SUBSTR(REGEXP_SUBSTR(CONCAT(';', list),';ir-[^01;]+'),LENGTH(';ir-')+1,LENGTH(REGEXP_SUBSTR(CONCAT(';',list),';ir-[^01;]+'))), ' ') AS result
[\CODE]
But it doesn’t work because “ir” can repeat in other parameters.
“ir-something-01” only appears once.
Is it in oracle a logic similar to result groups in oracle?
best regards,
Ricardo Tomás

rctomas wrote:
Hi,
In java I’m able to do find the right expression to retrieve what I wantWell, would be nice to tell us what that right expression would be :). Anyway, is this what you are looking for:
SQL> SELECT REGEXP_SUBSTR(';first field;ir-second field-02;ir-second field-01; third field',';ir-([^;]*)-01')
  2  from dual
  3  /
REGEXP_SUBSTR(';FIR
;ir-second field-01
SQL> SY.

Similar Messages

  • How to get substring from string starting from the end of string

    Hi
    How to cut from string:
    $A=C:\ClusterStorage\Volume1\WXP-plwropc300\Virtual Hard Disks\WXP-PLWROPC300_EE20E00F-315E-4781-A6DE-68497D4189B8.avhdx
    this substring (name of VHD file): WXP-PLWROPC300_EE20E00F-315E-4781-A6DE-68497D4189B8.avhdx
    This script should be universal so the best way to be cut all leters from the end of string $A till get the first mark \
    Thank you for help.
    Tomasz
    Kind Regards Tomasz

    PS > Split-Path 'C:\ClusterStorage\Volume1\WXP-plwropc300\Virtual Hard Disks\WXP-PLWROPC300_EE20E00F-315E-4781
    -A6DE-68497D4189B8.avhdx' -leaf
    WXP-PLWROPC300_EE20E00F-315E-4781-A6DE-68497D4189B8.avhdx
    PS >
    That is what "Split-Path" is for:
    ¯\_(ツ)_/¯

  • How to get substring from string using index?

    hi,
    here i am having string ,
    i want the pullareddy from below line ,
    i know how to get from substring.
    but i want to get the above using "index",
    can any help how to do it?
    String str1="janapana,pullareddy, in malaysia";
    jpullareddy

    get the start index with indexAt("pullareddy")
    get the end index with adding the length of the word to the start
    get the char[] of str1 with toCharArray()
    make a new string with the chars from start to end index.

  • How to specify ");" as a regular expression in split method of String class

    How to specify ");" as a regular expression in split method of String class using delimeters?

    Sorry, you can't specify that by using delimiters. Mostly because this requirement makes no sense.
    Do you rather need "\\);"?

  • Get chars from string of numerals

    here is what I would like to accomplish:
    Put the last four integers of the systemDate into a variable so I can do some math with them.
    Thanks.

    Excellent.  Thank you for the info.  Very helpful.
    Dewey
    From: jchunick [email protected]
    Sent: Friday, June 03, 2011 4:20 PM
    To: Dewey Parker
    Subject: Re: get chars from string of numerals
    This is a post I made for the wiki which should help: http://director-online.com/dougwiki/index.php?title=Undocumented_Lingo#the_systemDate

  • Cannot get regular expression to return true in String.matches()

    Hi,
    My String that I'm attempting to match a regular expression against is: value=='ORIG')
    My regular expression is: value=='ORIG'\\) The double backslashes are included as a delimiter for ')' which is a regular expression special character
    However, when I call the String.matches() method for this regular expression it returns false. Where am I going wrong?
    Thanks.

    The string doesn't contain what you think it contains, or you made a mistake in your implementation.
    public class Bar {
       public static void main(final String... args) {
          final String s = "value=='ORIG')";
          System.out.println(s.matches("value=='ORIG'\\)")); // Prints "true"
    }

  • OR ('|') in regular expressions (e.g. split a String into lines)

    Which match gets used when you use OR ('|') to specify multiple possible matches in a regex, and there are multiple matches among the supplied patterns? The first one (in the order written) which matches? Or the one which matches the most characters?
    To make this concrete, suppose that you want to split a String into lines, where the line delimiters are the same as the [line terminators used by Java regex|http://java.sun.com/javase/6/docs/api/java/util/regex/Pattern.html#lt] :
         A newline (line feed) character ('\n'),
         A carriage-return character followed immediately by a newline character ("\r\n"),
         A standalone carriage-return character ('\r'),
         A next-line character ('\u0085'),
         A line-separator character ('\u2028'), or
         A paragraph-separator character ('\u2029)
    This problem has [been considered before|http://forums.sun.com/thread.jspa?forumID=4&threadID=464846] .
    If we ignore the idiotic microsoft two char \r\n sequence, then no problem; the Java code would be:
    String[] lines = s.split("[\\n\\r\\u0085\\u2028\\u2029]");How do we add support for \r\n? If we try
    String[] lines = s.split("[\\n\\r\\u0085\\u2028\\u2029]|\\r\\n");which pattern of the compound (OR) regex gets used if both match? The
    [\\n\\r\\u0085\\u2028\\u2029]or the
    \\r\\n?
    For instance, if the above code is called when
    s = "a\r\nb";and if the first pattern
    [\\n\\r\\u0085\\u2028\\u2029]is used for the match when the \r is encountered, then the tokens will be
    "a", "", "b"
    because there is an empty String between the \r and following \n. On the other hand, if the rule is use the pattern which matches the most characters, then the
    \\r\\n
    pattern will match that entire \r\n and the tokens will be
    "a", "b"
    which is what you want.
    On my particular box, using jdk 1.6.0_17, if I run this code
    String s = "a\r\nb";
    String[] lines = s.split("[\\n\\r\\u0085\\u2028\\u2029]|\\r\\n");
    System.out.print(lines.length + " lines: ");
    for (String line : lines) System.out.print(" \"" + line + "\"");
    System.out.println();
    if (true) return;the answer that I get is
    3 lines:  "a" "" "b"So it seems like the first listed pattern is used, if it matches.
    Therefore, to get the desired behavior, it seems like I should use
    "\\r\\n|[\\n\\r\\u0085\\u2028\\u2029]"instead as the pattern, since that will ensure that the 2 char sequence is first tried for matches. Indeed, if change the above code to use this pattern, it generates the desired output
    2 lines:  "a" "b"But what has me worried is that I cannot find any documentation concerning this "first pattern of an OR" rule. This means that maybe the Java regex engine could change in the future, which is worrisome.
    The only bulletproof way that I know of to do line splitting is the complicated regex
    "(?:(?<=\\r)\\n)" + "|" + "(?:\\r(?!\\n))" + "|" + "(?:\\r\\n)" + "|" + "\\u0085" + "|" + "\\u2028" + "|" + "\\u2029"Here, I use negative lookbehind and lookahead in the first two patterns to guarantee that they never match on the end or start of a \r\n, but only on isolated \n and \r chars. Thus, no matter which order the patterns above are applied by the regex engine, it will work correctly. I also used non-capturing groups
    (?:X)
    to avoid memory wastage (since I am only interested in grouping, and not capturing).
    Is the above complicated regex the only reliable way to do line splitting?

    bbatman wrote:
    Which match gets used when you use OR ('|') to specify multiple possible matches in a regex, and there are multiple matches among the supplied patterns? The first one (in the order written) which matches? Or the one which matches the most characters?
    The longest match wins, normally. Except for alternation (or) as can be read from the innocent sentence
    The Pattern engine performs traditional NFA-based matching with ordered alternation as occurs in Perl 5.
    in the javadocs. More information can be found in Friedl's book, the relevant page of which google books shows at
    [http://books.google.de/books?id=GX3w_18-JegC&pg=PA175&lpg=PA175&dq=regular+expression+%22ordered+alternation%22&source=bl&ots=PHqgNmlnM-&sig=OcDjANZKl0VpJY0igVxkQ3LXplg&hl=de&ei=Dcg7S43NIcSi_AbX-83EDQ&sa=X&oi=book_result&ct=result&resnum=1&ved=0CA0Q6AEwAA#v=onepage&q=&f=false|http://books.google.de/books?id=GX3w_18-JegC&pg=PA175&lpg=PA175&dq=regular+expression+%22ordered+alternation%22&source=bl&ots=PHqgNmlnM-&sig=OcDjANZKl0VpJY0igVxkQ3LXplg&hl=de&ei=Dcg7S43NIcSi_AbX-83EDQ&sa=X&oi=book_result&ct=result&resnum=1&ved=0CA0Q6AEwAA#v=onepage&q=&f=false]
    If this link does not survive, search google for
    regular expression "ordered alternation"
    My first hit went right into Friedl's book.
    Harald.

  • Using regular expressions to get a customized output

    Hi,
    I have a string/varchar variable with the data ',a,b,c,' in it.
    I want the display as follows:
    a
    b
    c
    I would like to get the similar output using regular expressions.
    How do I get this output using REGEXP_REPLACE or REGEXP_SUBSTR?
    Please do the needful.
    Thanks & Regards,
    Rakshit

    I remember that, however if we look closer, that one has a little flaw: The 2nd row should be null, because ",," indicates an empy field. The MODEL clause solution works just fine in this case:
    with t as (select 'aaaa,,bbbb,cccc,dddd,eeee,ffff' col1 from dual)
    -- end of sample data
    SELECT col_new
      FROM t
    MODEL
       PARTITION BY (ROWNUM rn)
       DIMENSION BY (0 dim)
       MEASURES(col1, col1 col_new)
       RULES ITERATE(99) UNTIL (ITERATION_NUMBER = LENGTH(REGEXP_REPLACE(col1[0], '[^,]')))
                    (col_new[ITERATION_NUMBER] = REPLACE(REGEXP_SUBSTR(col1[0], '(^|,)[^,]*', 1, ITERATION_NUMBER+1), ','))
    COL_NEW                                                                                                                                                                  
    aaaa                                                                                                                                                                     
    bbbb                                                                                                                                                                     
    cccc                                                                                                                                                                     
    dddd                                                                                                                                                                     
    eeee
    ffff
    7 Zeilen ausgewählt.Update: I had this nagging feeling that I missed something, and there it was. If you want to see what the problem with my solution is, change the example to
    with t as (select ',aaaa,,bbbb,cccc,dddd,eeee,ffff' col1 from dual)So I went back and tried to fix BlueShadows approach. Here it is:
    with t as (select 'aaaa,,bbbb,cccc,dddd,eeee,ffff' txt from dual)
    -- end of sample data
    SELECT REPLACE(REGEXP_SUBSTR(',' || txt, ',[^,]*', 1, level), ',') col_new
      FROM t
      CONNECT BY level <= length(regexp_replace(txt,'[^,]*'))+1
    ;C.

  • How to extract substring from string... how to find the index?

    suppose i have a string like
    "string1 string2 string3 string4 string....stringK...stringN"
    i would like to extract the substring from string4 to stringK-1
    where stringK and string3 are pre defined strings (ie, i know exactly what stringK and string3 is).
    is there a function to extract the substring from string4 to stringK-1
    or is there a function i can use to determine the index of the end of string4 and the start of stringK?
    thks!

    If your substrings are seperated by a space (or by any other character that isn't used in any of the substrings), you could use something like StringTokenizer.
    If you wanna get real fancy, use the split method of String.

  • Regular expression to remove SIDs from list

    Hey everyone so I have a script and in it I try to find the current user, as well as the last user. Currently I'm using a regular expression to throw the System account SIDs and other things like that out of the list. However this doesn't seem to be taking
    SQL SIDs out of my list ie. ReportServer$LOCAL with the SID S-1-5-80-4264962431-3932693095-1576469926-235475122-2208986020
    What's the best way to get only user SIDs?
    Here's what I have so far:
    $Win32User = Get-WmiObject -Class Win32_UserProfile -ComputerName $Computer
    $Win32User = $Win32User | Where-Object {($_.SID -notmatch "^S-1-5-\d[18|19|20]$")}
    $Win32User = $Win32User | Sort-Object -Property LastUseTime -Descending
    $LastUser = $Win32User | Select-Object -First 1
    When I can this it breaks since there is no actual user tied to this SID:
    $UserSID = New-Object System.Security.Principal.SecurityIdentifier($LastUser.SID)
    $User = $UserSID.Translate([System.Security.Principal.NTAccount])
    Thanks for any help!!

    Start cmd.exe as your domain user and run whoami /user to get your own SID. You will get something like this:
    USER INFORMATION
    User Name SID
    ========================= =============================================
    DEMOSYSTEM\CustomAccount1 S-1-5-21-3419697060-3810377854-678604692-1000
    The last part of the SID, in this case 1000, is called RID. When you create a new user or computer object in your domain, only the RID will be different from your own SID. The RID starts on 1000 and increments as you create new objects.
    If you are only interested in user accounts from the same domain as your user, you can use a regex like this, only based on your own SID:
    $_.SID -match '^S-1-5-21-3419697060-3810377854-678604692-[\d]{4,10}$'

  • Get number from string

    Hi,
    I have a problem with an select.
    I need to compare two string columns. First column includes only a number with 9 characters:
    '001234567'
    Second column includes text where somewhere inside this text is the number 001234567.
    'Hallo1 001234567'
    I need to extract the 9 character big number out of the string. I thought using the regular expression feature could help me.
    SELECT
      REPLACE(REGEXP_REPLACE('hallo 001122334', '[a-z]', ''),' ') "REGEXP_REPLACE"
    FROM dual;But this would exclude the number 1 after Hallo:
    Result: '1001234567'
    The number I look for is always 9 character long.
    Thanks ahead,
    Tobias

    You have many variants:
    with your_table as
         (select
                'hallo1001122334' first_column,
                '001122334' second_column
          from dual
    select *
    from your_table
    where
    --1) regexp_like(first_column,'.*'||second_column||'$')
    --2) first_column like '%'||second_column
    --3) regexp_substr(first_column,'\d{9}$')=second_column
    --4) regexp_replace(first_column,'\D','') like '%'||second_columnFourth variant - includes case when chars can be between numbers in first column (for example 'hallo100a1a1a2a2a3a3a4').

  • Creating regular expression to get desired info

    Hi all!!!
    I have a little problem. I need to get the line below, but i NEED to use regular expression. I am useing java.text.regex correctly, but I dont really know how to create a regex pattern. my line is :
    [2004/01/06 12:43:58.735] [info] br.com.organox.web.aggregator.servlet.struts.action.LoginEmbeddedAction: User 'TESTER12345678' with ticket 'acLBF9a6ZiY41073400238626' logged in.
    and i need to get these two values
    'TESTER12345678' and 'logged in'
    can anyone help me?

    You could try this:
    String line = "[2004/01/06 12:43:58.735] [info] br.com.organox.web.aggregator.servlet.struts.action.LoginEmbeddedAction: User 'TESTER12345678' with ticket 'acLBF9a6ZiY41073400238626' logged in.";
    String pattern = "User '(.+?)'.+' (.+)";
    Pattern p = Pattern.compile(pattern);
    Matcher m = p.matcher(line);
    String user = null;
    String status = null;
    if (m.find())
        user = m.group(1);
        status= m.group(2);
    System.out.println("user=" + user + ", status=" + status);By the way, next time post at the "Jave programming" forum instead.

  • How to get InputStream from String ?

    Hi !
    I want to get InputStream object from String.
    String str = "balabalabala";
    InputStream stream = getInputStream(str);
    How to realize getInputStream(str) function ?
    Thanks!

    The preferred method nowadays is to use Readers and Writers for String data - hence StringReader(String). If you're going to operate on the InputStream directly, then I'd modify your code to use the Reader calls and go that route.
    If, however, you need to pass the InputStream to some other piece of API that requires an InputStream instead of a Reader, then the ByteArrayInputStream is probably your best bet. StringBufferInputStream is deprecated because it doesn't work reliably in the face of many character encodings.
    Speaking of encodings - never call Strng.getBytes() - always use the getBytes(character-encoding) version, so you KNOW what encoding you're getting!
    Grant

  • Using Regular Expressions to replace Quotes in Strings

    I am writing a program that generates Java files and there are Strings that are used that contain Quotes. I want to use regular expressions to replace " with \" when it is written to the file. The code I was trying to use was:
    String temp = "\"Hello\" i am a \"variable\"";
    temp = temp.replaceAll("\"","\\\\\"");
    however, this does not work and when i print out the code to the file the resulting code appears as:
    String someVar = ""Hello" i am a "variable"";
    and not as:
    String someVar = "\"Hello\" i am a \"variable\"";
    I am assumming my regular expression is wrong. If it is, could someone explain to me how to fix it so that it will work?
    Thanks in advance.

    Thanks, appearently I'm just doing something weird that I just need to look at a little bit harder.

  • A regular expression to detect a blank string...

    Anyone know how to write a regular expression that will detect a blank string?
    I.e., in a webservice xsd I'm adding a restriction to stop the user specifying a blank string for an element in the webservice operation call.
    But I can't figure out a regular expression that will detect an entirely blank string but that will on the other hand allow the string to contain blank spaces in the text.
    So the restriction should not allow "" or " " to be specified but will allow "Joe Bloggs" to be specified.
    I tried [^ ]* but this wont allow "Joe Bloggs" to pass.
    Any ideas?
    Thanks,
    Ruairi.

    Hi ruairiw,
    there is a shortcut for the set of whitespace chars in Java. It is the Expression *\s* which is equal to *[ \t\n\f\r\u000b]*.
    With this expression you can test whether a String consists only of whitespace chars.
    Expamle:
    String regex = "\\s*"; // the slash needs to be escaped
    // same as String regex = "[ \t\n\f\r\u000b]";
    System.out.println("".matches(regex)); // true
    System.out.println("   ".matches(regex)); // true
    System.out.println("  \r\n\t ".matches(regex)); // true
    System.out.println("\n\nTom".matches(regex)); // false
    System.out.println("   Tom Smith".matches(regex)); // falseBesh Wishes
    esprimo

Maybe you are looking for

  • How to connect to specific Airport

    I have a new Airport Extreme-N which is hardwired to the internet. In another room I have an Express that I use to connect to my DVR to get "on demand" programming. I am using the Extend this network option on the Express. I am noticing that the iMac

  • Error 22:

    Error 22: Windows does not have a constructor. Line: 388 -> var w= new window(res); I get this message when trying to use File/ Automate/ Merge to HDR in Photoshop CS5 (32), using Windows XP sp3. Any suggestions? Thanks, Kathleen

  • The operation cannot complete because of an unknown error. [-1]

    For the last month or so I have been getting this error everytime I open up a document in Illustrator CS5.1. I have read that this could be font related, but eliminated all fonts that had errors. I have read that it could be from opening files across

  • RVL200 and SRW2008 VLAN setup

    I have the RVL200 as my internet gateway and i have 3 VLAN's configured. i have set port 4 as my trunk and added all VLAN's to that port as tagged. I have setup a subnet for each of the VLAN's. My question is what do i need to do on the SRW2008 so th

  • Ejecting the windows disc

    Ok, tonight I got a new macbook. I decided to get boot camp over with, so I started to install and all that. I successfully intalled windows; right now I'm at the part where I need to eject the windows install disc and put in the Leopard disc to inst