Extract string between two parts

Hi all,
I am trying to extract a string using the regexp substr with no luck:
string is :
ws-servername.domain name
example:
ws-db1.mydomain
desired outcome :
servername only
any ideas ?
Thanks
Yoav

SELECT Regexp_Substr('ws-servername.domain name',
                     '[^\.^\-]+',
                     1,
                     Rn + 1)
FROM   (SELECT Regexp_Count('ws-servername.domain name',
                            '[-]+') Rn
        FROM   Dual)Edited by: Sen on Dec 6, 2011 5:14 AM

Similar Messages

  • How would I split a string between two strings?

    Hi Guys,
    I have a question hopefully you guys can help with..
    I have a set of data similar to
    sefsfesef<1111>Example<2222>desefsefsefefsefsef<1111>Example2<2222>sefsefsef
    What I want to do is split my string between the <1111> and <2222> and get "Example" and "Example2" back... is this possible in Java? Possibly using regular expressions of sorts. I'm a little lost, any help would be much appreciated!
    Thanks,
    Vasant

    Here is an example (parse.java) that will work provided that the content between <1111> and <2222> does not contain the < character.
    import java.util.regex.*;
    public class parse {
      public static void main(String args[]) {
        String teststring = "sefsfesef<1111>Example<2222>desefsefsefefsefsef<1111>Example2<2222>sefsefsef";
        Pattern p = Pattern.compile("<1111>([^<]*)<2222>");
        Matcher m = p.matcher(teststring);
        while(m.find()) {
          System.out.println(m.group(1));
    }I'm sure some regex guru around here could solve this one in 3 characters or less, but that ain't me :)

  • Regex: Extracting text between two HTML tags

    Hello,
    the common answer to this question would be
    <tag>(.*)</tag>
    or
    <tag>[^<]*But I have LFs (and whitespace) around the tags:
    <html>
      <body>
        One text line to be retrieved.
      </body>
    </html>So I tried
    (?s)<body>(.*)</body>But that didn't help.
    What's missing?

    Thanks for your replies.
    @Sabre
    I tried your suggestion with the following code to no avail
    import java.util.*;
    import java.util.regex.*;
    public class X {
      public static void main(String[] args) {
          String s=
    "<html>\n"+
    "  <head>\n"+
    "\n"+
    "  </head>\n"+
    "  <body>\n"+
    "    One <u>text line</u> to be retrieved.\n"+
    "  </body>\n"+
    "</html>";
        String regex= "<body>([^<]*)</body>";
        Pattern p = Pattern.compile(regex); // Create the pattern.
        Matcher matcher = p.matcher(s); // Create the matcher with the string.
        while (matcher.find()) {
          System.out.printf("Found: \"%s\" from %d to %d.%n",
                   matcher.group(), matcher.start(), matcher.end()-1);
    }@ejp
    Paul had a similar objection. But as I've written, my html string will always have this same structure and all I have to do is to extract the text. So if regex doesn't work in that case, I'd rather prefer two indexOf-s instead of bothering a parser.

  • Extract substrings between two words

    public class test
      public static void testing()
         String text = "<div>teext</div>sdfaf<div id='ii'>wwwwwww</div><div>nice</div>";
         String left = "<div>";
         String right = "</div>";
         int start = text.indexOf(left);
         int end = text.indexOf(right);
         int linkNum = 0;
         String[] parts = new String[50];
         while ((start = text.indexOf(left, start)) != -1) {
              start = text.indexOf(left, start);
              end = text.indexOf(right, end);
              parts[linkNum] = left + text.substring(start+1, text.indexOf(left, start+1));
              linkNum++;
              start = (end + 1);
         for (int i=0; i<parts.length; i++)     {
              System.out.println("find: " + parts);
    public static void main(String[] args) throws Exception {
         testing();
    must output
    find: teext
    find: nice
    but i have the following error
    Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -42
            at java.lang.String.substring(String.java:1444)
            at test.testing(test.java:15)
            at test.main(test.java:24)
    Press any key to continue...
    Can you plese tell me what's the problem ? Tnx
    Edited by: beginner1983 on Jun 8, 2009 7:14 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    String regex = "(?s)(?<=<div>).*?(?=</div>)"; That will work in this case because the start tags don't contain any attributes. If there may be attributes, and you don't know or care which attributes and values will be present, you would use something like this for the start tag: "<div[^<>]*>"; But you can't use that in a lookbehind, because there's no obvious upper limit to the number of characters it can match. (That requirement is peculiar to Java, by the way; among other regex flavors, some permit only fixed-length matches in lookbehinds, while others place no restrictions on them at all.)
    I'm with da.futt on this point: lookarounds should never be your first resort. Lookbehinds, especially, are much trickier than most people expect on first encountering them. You tend to find yourself going through ridiculous contortions trying to fit them into the overall regex. Lookaheads are much easier to work with, but you have to be careful to keep them in sync with your expectations; the can be slippery.
    In this case, your first impulse should have been to do a straight match of the whole element, with a capturing group to extract the element's content: String regex = "(?s)<div>(.*?)</div>";
    while (m.find()) {
        System.out.println(m.group(1));
    } By the way, my copy of the [Regular Expressions Cookbook|http://www.amazon.com/gp/product/0596520689?ie=UTF8&tag=jgsbookselection&linkCode=as2&camp=1789&creative=390957&creativeASIN=0596520689] arrived the other day, and it did not disappoint. Good, solid stuff there.

  • Find string between two characters -- regex?

    So this seems like a regex type thing, but I'm still incredibly regex illeterate. If I have an offset in a string, I want to find all words separated by the space before and the space following that location.
    For Example:
    "This is a string of multiple characters"  
    If my cursor was between the o and the f in "of" i would want to return "string of multiple". I can then split this into an array of words using "\s" as a delimeter. I just need to get the substring shown.
    CLA, LabVIEW Versions 2010-2013

    Yamaeda wrote:
    Or you split the string at the Offset, reverse the first half, look for the 2nd space in each (which can be a regex, similar to [^\s]*[^\s]*) then revese back and recombine.
    /Y
    Droppin' knowledge.
    CLA, LabVIEW Versions 2010-2013

  • Scan from string and extract string between delimiter

    Hello,
    Basic questions.  Is it possible with the scan from string regular expression to extract the string that are within the specified delimiters.  Here is an example:
    \\Name of folder 1\Name of folder 2\Name of folder 3\File Name
    Can the scan from string output the following by specifying the right regular expression:
    Name of folder 1
    Name of folder 2
    Name of folder 3
    File Name
    I have tried \\\\%s\\%s\\%s\\%s but the %s stops at the first white space.
    Thanks,
    Michel
    Solved!
    Go to Solution.

    RavensFan suggested the appropriate function for your requirement, however you can also use an alternative, which is 'Spreadsheet String To Array'.
    I am not allergic to Kudos, in fact I love Kudos.
     Make your LabVIEW experience more CONVENIENT.

  • Add a buffer space between two parts of formula

    I have a formula that combines a date command (field) and some text at the end.  It's repeated for each row of a cross-tab, so they are stacked vertically.  I need to add a buffer of blank space in between the date command and the text at then end, so that each row looks the same no matter how long the month text is in my date field.
    Formula:
    ToText({Command.MyDate}, "MMMM yy")  & "             " &            "   MyText  "
    For example, when the date is April 2014 it would look like:
    "April 2014             My Text"                  But if the date is September 2014 it looks like:
    "September 2014          My Text"
    I would like for the MyText's to line up.  As you can see in my formula I thought entering a set amount of blank spaces would somehow add this buffer, but it didn't and I understand why.
    I should probably explain why I'm even doing this.  I have a cross tab in a report and I need a label to repeat for each row in addition to the Row Name.  The number of rows is always changing, so I can't use static text boxes.  The best way I found was to add the additional labels to the Row Name using a formula.
    Any advice is appreciated!

    OK. Here's another way to do this:
    1) Modify your existing formula and remove the spaces and customer text:
    ToText({Command.MyDate}, "MMMM yy")
    2) Create another formula that contains the label you wish to see for each row:
    "My Text"
    3) Go to the crosstab expert > Add the first formula and then add the second formula as well as the 'Row'
    4) Go to the Customize Style tab > Under 'Rows' highlight the second formula > Check 'Suppress Subtotal'
    5) Click the 'Format Gridlines' button > Select the first row 'Row labels vertical lines' > Change its color to White
    Refresh and let me know if this is what you're looking for.
    -Abhilash

  • Use query string between two custom New Form

    Hi guys,
    i have a New Form . In this  form i have  a button that open(onClick) another list form (it is a  different list). I have to pass a field value from the first form to the other . How can i do this using query string?Help please!
    Thank you!

    To pass some value with query string, you just need to open the form url with the querystring parameters (jquery needed):
    var url = '<yourlist>/newform.aspx?parameter1=' + $('input[Title="Title"]').val()
    SP.UI.ModalDialog.ShowPopupDialog(url)
    on the second newform.aspx, you can grab the querystring parameters with the Sharepoint native function "_spGetQueryParam('<lower case query key>')"
    var x = _spGetQueryParam("parameter1")
    Note: make sure you use the key as lowercase, even you if pass it with chars in uppercase.

  • Trim between two strings inside a column

    Hello,
    I have a large data in clob column and string between two values needs to be trimmed to 10 bytes.
    ie. - I need to trim string between <Val> and </Val> to 10.
    CLOB_COL
    <Val>123 Main Street</Val><Addr></Addr><Val>321 Main Street</Val><OtherNode></OtherNode>
    And, I would like my result to be:
    <Val>123 Main S</Val><Addr></Addr><Val>321 Main S</Val><OtherNode></OtherNode>
    What will be the fastest way to update this clob column or probably insert into a new table. (I do not have XML DB installted on this database, so I cannot use XML parser)
    Thanks

    Hi,
    Sorry, I made a mistake.
    Try this:
    SELECT  REGEXP_REPLACE ( '<Val>2010-10-31 16:59:24</Val>'
                            , '(<Val>[^<]{1,3000})'    || -- \1 = <Val> and up to 3000 characters (not <)
                                 '[^<]*'               || -- 0 or more characters (not <) to be removed
                     '(\</Val>)'               -- \2 = </Val>
                            , '\1\2'
                            )     AS val_substring
    FROM    dual;A plus-sign in a pattern means the preceding is repeated 1 or more times.
    I meant to use an asterisk to mean 0 or more times on this row:
    ...                          '[^<]*'               || -- 0 or more characters (not <) to be removed
    --                     +  was here originally 
    By the way, you may have noticed that this site normally doesn't display multiple spaces in a row.
    Whenever you post formatted text (including, but not limited to, code) on this site, type these 6 characters:
    \(small letters only, inside curly brackets) before and after each section of formatted text, to preserve spacing.
    This is especially helpful with regular expressions, not only because they're confusing enough with formatting, but because they use brackets which this site may interpret as markup and not print correctly.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Substring between two words from a clob

    How to extract a string between two words from a clob variable in PL/SQL?

    My requirement is to extract the soap envelope from a clob. In the below code l_response returned from the http request is a clob with the below format. I need to extract all the text that is between '<s:Envelope' and 's:Envelope>'. That means I need to get rid of the first 5 lines and the last line from the l_response. Can you please help me with the logic?
    --uuid:18cb22a2-11cc-43f4-bfea-c213da179d30+id=157
    Content-ID: <http://tempuri.org/0>
    Content-Transfer-Encoding: 8bit
    Content-Type: application/xop+xml;charset=utf-8;type="application/soap+xml"
    <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing"><s:Header><a:Action s:mustUnderstand="1">http://tempuri.org/IUpdateService/QueryUpdateLogRecordsResponse</a:Action><a:RelatesTo>urn:uuid:413f419c-f489-44ea-bd12-dff6f24a4d71</a:RelatesTo></s:Header><s:Body><QueryUpdateLogRecordsResponse xmlns="http://tempuri.org/"><QueryUpdateLogRecordsResult xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:x="http://www.w3.org/2001/XMLSchema"><XObject.m_element i:type="x:string" xmlns="">&lt;QueryResult Count="2" NextStart="0" PreviousStart="0" Id="{AD62FD77-AFBE-4362-BBEF-695DA5D92640}"&gt;&lt;Columns Count="33"&gt;&lt;Column AttributeName="Id" 
    … 5 pages later…
    DateModified="2014-07-06 07:34:41.9129549-07:00" /&gt;&lt;/Records&gt;&lt;/QueryResult&gt;</XObject.m_element></QueryUpdateLogRecordsResult></QueryUpdateLogRecordsResponse></s:Body></s:Envelope>
    --uuid:18cb22a2-11cc-43f4-bfea-c213da179d30+id=157—
    DECLARE
       l_request             VARCHAR2 (4000);
       l_http_req            UTL_HTTP.req;
       l_http_resp           UTL_HTTP.resp;
       v_buffer              VARCHAR2 (32767);
       n_next_start_record   NUMBER (20) := 1;
       l_response            CLOB;
    BEGIN
       -- Call webservices. Works fine
       l_request :=
             '--uuid:e4c19840-745d-45b2-90ca-12d71be4cfd9+id=2'
          || CHR (13)
          || CHR (10)
          || 'Content-ID: <http://tempuri.org/0>'
          || CHR (13)
          || CHR (10)
          || 'Content-Transfer-Encoding: 8bit'
          || CHR (13)
          || CHR (10)
          || 'Content-Type: application/xop+xml;charset=utf-8;type="application/soap+xml"'
          || CHR (13)
          || CHR (10)
          || CHR (13)
          || CHR (10)
          || '<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing"><s:Header><a:Action s:mustUnderstand="1">http://tempuri.org/IUpdateService/QueryUpdateLogRecords</a:Action><a:MessageID>urn:uuid:413f419c-f489-44ea-bd12-dff6f24a4d71</a:MessageID><a:ReplyTo><a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address></a:ReplyTo><a:To s:mustUnderstand="1">http://dexdb5/DexNETWebServices_4_0_0_4/UpdateService.svc</a:To></s:Header><s:Body><QueryUpdateLogRecords xmlns="http://tempuri.org/"><context xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:x="http://www.w3.org/2001/XMLSchema"><XObject.m_element i:type="x:string" xmlns="">&lt;OnlineContext SystemId="'
          || g_system_id
          || '" SessionId="'
          || g_session_id
          || '" UserId="'
          || g_user_id
          || '" /&gt;</XObject.m_element></context><xQueryRequest xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:x="http://www.w3.org/2001/XMLSchema"><XObject.m_element i:type="x:string" xmlns="">&lt;QueryRequest Start="'
          || p_next_start_record
          || '" Count="'
          || g_records_count
          || '" Distinct="0" OrderBy="" Condition="(oUpdateLog.DateCreated &amp;gt;= '''
          || p_last_load_time
          || ''')" ColumnInfo="1" /&gt;</XObject.m_element></xQueryRequest></QueryUpdateLogRecords></s:Body></s:Envelope>'
          || CHR (13)
          || CHR (10)
          || '--uuid:e4c19840-745d-45b2-90ca-12d71be4cfd9+id=2--';
       l_http_req :=
          UTL_HTTP.begin_request (g_query_updatelog_records_url, 'POST', 'HTTP/1.1');
       UTL_HTTP.set_header (l_http_req, 'MIME-Version', '1.0');
       UTL_HTTP.set_header (
          l_http_req,
          'Content-Type',
          'multipart/related; type="application/xop+xml";start="<http://tempuri.org/0>";boundary="uuid:e4c19840-745d-45b2-90ca-12d71be4cfd9+id=2";start-info="application/soap+xml"');
       UTL_HTTP.set_header (
          l_http_req,
          'VsDebuggerCausalityData',
          'uIDPo5F/qXRc4YJImqB6Ard30cQAAAAAAjIXinpIVUulXLJOsSG7yyv7Lf2yHgpHlIxvc6oeqaAACQAA');
       UTL_HTTP.set_header (l_http_req, 'Content-Length', LENGTH (l_request));
       UTL_HTTP.write_text (l_http_req, l_request);
       DBMS_LOB.createtemporary (l_response, FALSE);
       l_http_resp := UTL_HTTP.get_response (l_http_req);
       BEGIN
          LOOP
             UTL_HTTP.read_text (l_http_resp, v_buffer, 32767);
             DBMS_OUTPUT.put_line (v_buffer);
             DBMS_LOB.writeappend (l_response, LENGTH (v_buffer), v_buffer);
          END LOOP;
       EXCEPTION
          WHEN UTL_HTTP.end_of_body
          THEN
             NULL;
       END;
       UTL_HTTP.end_response (l_http_resp);
       l_response := DBMS_XMLGEN.CONVERT (xmldata => l_response, flag => 1);
       -- Extract the soap envelope from clob. Issue because of the 32767 characters limitation
       SELECT    DBMS_LOB.SUBSTR (                  -- Problem here
                    l_response,
                      INSTR (l_response, 's:Envelope>', -1)
                    - INSTR (l_response, '<s:Envelope'),
                    INSTR (l_response, '<s:Envelope'))
              || 's:Envelope>'
         INTO l_response
         FROM DUAL;
          -- Parse the xml. Works fine once the above issue is fixed
          SELECT xt.nextstart
            INTO n_next_start_record
            FROM XMLTABLE (
                    xmlnamespaces ('http://www.w3.org/2003/05/soap-envelope' AS "s",
                                   'http://tempuri.org/' AS "data"),
                    's:Envelope/s:Body/data:QueryUpdateLogRecordsResponse/data:QueryUpdateLogRecordsResult/XObject.m_element/QueryResult'
                    PASSING xmltype (l_response)
                    COLUMNS nextstart NUMBER (20) PATH '@NextStart') xt;
       DBMS_OUTPUT.put_line ('NextStart ' || n_next_start_record);
    END;

  • Split String into two

    HI,
    How to Split String into two parts at delimiter

    HI,
    REPORT ZSTRING.
    DATA: LENGTH TYPE I,    
          REMAINING_LENGTH TYPE I ,   
          NEXT_POINTER TYPE I    ,   
          FIRST_HALF(20)  TYPE C ,    
          SECOND_HALF(20) TYPE C ,    
          TEMP TYPE I .
    PARAMETER: WORD(35) TYPE C . "INPUT WORD
    START-OF-SELECTION.
    LENGTH = STRLEN( WORD ).      "Length of the input String
    SEARCH WORD FOR '/'.
        IF SY-SUBRC = 0 .  
          IF SY-FDPOS > 0.   
          MOVE WORD+0(SY-FDPOS) TO FIRST_HALF.  
          ENDIF.  
       TEMP = SY-FDPOS + 1. 
       IF TEMP <> LENGTH.    
       NEXT_POINTER = SY-FDPOS + 1.    
       REMAINING_LENGTH = ( LENGTH - SY-FDPOS ) - 1.    
       MOVE WORD+NEXT_POINTER(REMAINING_LENGTH) TO SECOND_HALF.  
       ENDIF.
    ENDIF.
    WRITE:/'Input String:', WORD .
    WRITE:/'First  Half:', FIRST_HALF.
    WRITE:/'Second Half:', SECOND_HALF.
    *-- End of Program
    Reward Points if found helpfull..
    Cheers,
    Chandra Sekhar.

  • String function in Oracle 9i to find part of string having two positions

    Hi,
    We need to extract the part of string having start and end position.
    Like
    Suppose the string is "TYPE ref_cur_type IS REF CURSOR" and need to extract name of the ref cursor i.e ref_cur_type.The length of the output is not fixed. But not able to extract the exact string.
    Thanks,

    What is the criteria for part of string? Do you give start character and end character position like 3,9 etc? Or its just that the word that comes between two spaces?
    Cheers
    Sarma.

  • Regular expression help please. (extractin​g a string subset between two markers)

    I haven't used regular expressions before, and I'm having trouble finding a regular expression to extract a string subset between two markers.
    The string;
    Header stuff I don't want
    Header stuff I don't want
    Header stuff I don't want
    Header stuff I don't want
    Header stuff I don't want
    Header stuff I don't want
    ERRORS 6
    Info I want line 1
    Info I want line 2
    Info I want line 3
    Info I want line 4
    Info I want line 5
    Info I want line 6
    END_ERRORS
    From the string above (this is read from a text file) I'm trying to extract the string subset between ERRORS 6 and END_ERRORS. The number of errors (6 in this case) can be any number 1 through 32, and the number of lines I want to extract will correspond with this number. I can supply this number from a calling VI if necessary.
    My current solution, which works but is not very elegant;
    (1) uses Match Regular Expression to the return the string after matching ERRORS 6
    (2) uses Match Regular Expression returning all characters before match END_ERRORS of the string returned by (1)
    Is there a way this can be accomplished using 1 Match Regular Expression? If so could anyone suggest how, together with an explanation of how the regular expression given works.
    Many thanks
    Alan
    Solved!
    Go to Solution.

    I used a character class to catch any word or whitespace characters.  Putting this inside parentheses makes a submatch that you can get by expanding the Match Regular Expression node.  The \d finds digits and the two *s repeat the previous term.  So, \d* will find the '6', as well as '123456'.
    Jim
    You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice

  • Is there a way to delete text between two strings?

    In Pages, is there a way to delete all text containted between two strings?
    For example, if I have a text document that looks like this:
    String 1
    String 2
    Unwanted text
    Unwanted text
    String 3
    String 4
    Is there was to delete the unwanted text between string 2 and 3 so it looks like this:
    String 1
    String 2
    String 3
    String 4
    The unwanted text is differnet between documents but string 2 and 3 are constant. I want to do this via automator for the same strings on multiple documents.
    Any help is appreciated!

    Do you mean Pages '09 v4.3?
    There were some links here:
    https://discussions.apple.com/message/24051199#24051199
    Peter

  • Difference between two text(String) in percent

    I am currently building a project require to generate the differences between two text store in (String) in precentages. The fuction should look something likde this:
        double compare(String text1, String text2){
            //doing the smart comparison
            //return percentage in double
        }The text1 and text2 should be a long document and the compare function should return the percentage of difference of those texts. Examples of usage:
        System.out.println(
            compare(
        );Thanks for every reply. Please kindly correct me for any mistake.

    Let us define an elementary operation as one of
    1) inserttion of a character,
    2) deletion of a character or
    3) replacemen tof a character. Woo - my first ever post!
    The distance measure described in the above post is called the edit distance, or "Levenshtein distance". If you google that, you're bound to find some ready-made java code that does it for you.
    Happy hunting!
    Btw, I was chatting to a friend about distance measures. He was telling me about a proposed distance measure between two arbitrary files: You 1) zip both files together, and 2) zip the two files separately, then compare the file sizes of the two zip files. I love this idea! Apparently some guys compared files containing the same block of text in different languages, and were able to show that languages from the same language groups (eg slavic, germanic) cluster together.

Maybe you are looking for