REGEXP_INSTR on a multi line string

Hello ,
I am trying to search through a string that is stored with multi line and trying to find the first occurrence of a character.
For example : The string is -
"This is a sample
text to test
from [first string] to [second string] "
When i try to search for the first occurrence of "[" and "]" regular instr function is returning the complete string
This is the query i used:
The above string is stored in a varchar2 column named - comments
select substr(comments,instr(comments,'['),instr(comments,']')) from my_table
This above query returns : [first string] to [second string]
i assume instr returns the first occurence of a letter in the given string. i was looking for [first string] but it returns me both. Can this be replaced with regexp_instr function?.
Any help on this would be much appreciated.
Thanks

user619203 wrote:
Hello ,
I am trying to search through a string that is stored with multi line and trying to find the first occurrence of a character.
For example : The string is -
"This is a sample
text to test
from [first string] to [second string] "
When i try to search for the first occurrence of "[" and "]" regular instr function is returning the complete string
This is the query i used:
The above string is stored in a varchar2 column named - comments
select substr(comments,instr(comments,'['),instr(comments,']')) from my_table
This above query returns : [first string] to [second string]
i assume instr returns the first occurence of a letter in the given string. i was looking for [first string] but it returns me both. Can this be replaced with regexp_instr function?.
Any help on this would be much appreciated.
Thankslike this?
SQL> ed
Wrote file afiedt.buf
  1  with tmp as
  2  (
  3  select 'This is a sample
  4  text to test
  5  from [first string] to [second string]' txt from dual)
  6  select substr(txt, instr(txt, '['), instr(txt, ']') - instr(txt, '[') + 1)
  7* from   tmp
SQL> /
SUBSTR(TXT,INS
[first string]Also questions of these types are better asked in {forum:id=75} forum.

Similar Messages

  • Multi-line String - Match Regular Expression

    I am trying to figure out the format of a regular expression in order to pull select lines out of a multi-line string and populate those lines as individual elements of a string array while using Match Regular Expression. The overall length of the multi-line string can vary as well as the text contained within the string. The string can contain letters, numbers, and special characters. I have attached an example VI. Within the example VI I only want to return the lines beginning with "Device #" into the array. The number of lines beginning with "Device #" can vary but I want to capture them all.
    Or is there a better function to use instead of Match Regular Expression that will give me the desired outcome?  
    Solved!
    Go to Solution.
    Attachments:
    MultiLine Regular Expression.vi ‏22 KB

    aaronb wrote:
    I am trying to figure out the format of a regular expression in order to pull select lines out of a multi-line string and populate those lines as individual elements of a string array while using Match Regular Expression. The overall length of the multi-line string can vary as well as the text contained within the string. The string can contain letters, numbers, and special characters. I have attached an example VI. Within the example VI I only want to return the lines beginning with "Device #" into the array. The number of lines beginning with "Device #" can vary but I want to capture them all.
    Or is there a better function to use instead of Match Regular Expression that will give me the desired outcome?  
    Match Regular Expression works well for this.
    Ben64

  • Multi-line string - Array?

    I was wondering if someone could tell me how to take a multi-line
    string and dump it into an array. I'm assuming that I use the 'Pick
    Line' function in a while loop? What do I check for to terminate the
    loop?
    Thanks...
    -- N

    "kevin" wrote in message news:...
    > In article <[email protected]>, "Natalia"
    > wrote:
    >
    > > I was wondering if someone could tell me how to take a multi-line string
    > > and dump it into an array. I'm assuming that I use the 'Pick Line'
    > > function in a while loop? What do I check for to terminate the loop?
    > >
    > > Thanks...
    > >
    > > -- N
    >
    > Natalia,
    >
    > Use the 'Spreadsheet String to Array' vi. Use the End of Line delimiter
    > (or carriage return, depends on OS). Add a %s to the format string and
    > POOF!, an instant text array. No loops required. Oh yeah, you also need
    > to add an array string constant to the array type so the output comes ou
    t
    > as a string type instead of the default double.
    >
    > You can do it with you present method if you need the loops for other
    > stuff. To terminate the loop just look for a -1 in the output of 'Pick
    > Line' when searching for you CR or EOL. You just have to remember to dump
    > the last value.
    >
    > good luck,
    > - Kevin
    Kevin -
    Thank you. That did the trick.
    -- Natalia

  • JTable -showing column headers and displaying multi-line strings

    Hi,
    This is two questions really.
    #1 - Does anyone know why my column headers aren't showing in my jtable using the model below?
    #2 - Does anyone know how I can display, mulitple line strings in a jtable? Currently my newline character ('\n') is just being displayed as a character.
    any help very much appreciated,
    Tom
    private class TaskHistoryTableModel extends AbstractTableModel {
    private List taskHistory = new ArrayList();
    public Object getValueAt(int row, int col) {
    if (col == 0) {
    return ((TaskHistoryItem) taskHistory.get(row)).getText();
    } else {
    return ((TaskHistoryItem) taskHistory.get(row)).getDate().getTime();
    public int getRowCount() {
    return taskHistory == null ? 0 : taskHistory.size();
    public int getColumnCount() {
    return 2;
    /** Getter for property taskHistory.
    * @return Value of property taskHistory.
    public List getTaskHistory() {
    return taskHistory;
    /** Setter for property taskHistory.
    * @param taskHistory New value of property taskHistory.
    public void setTaskHistory(List taskHistory) {
    this.taskHistory = taskHistory;
    public String getColumnName (int col) {
    return col == 0 ? "Text" : "Entered At";
    public boolean isCellEditable(int row, int col) {
    return false;
    }

    fixed my own problem - make your mulit-line string into html format e.g.
    this string will appear on two lines in a jtable
    "<html><p>A much more interesting entry</p> <p>on multiple lines</p></html>"

  • Additional results doesn't work with multi-line string dat

    I observed an erratic behavior with "Additional Results" in TestStand 2010. The problem statement is as follows:
    1. I have a variable "Locals.FirstName"
    2. I have another variable "Locals.LastName"
    3. Concatenate these two strings with a line feed or a new line character (Locals.FirstName+"\n"+Locals.LastName) and display it in a XML report. 
    Approach:
    1. Using "Statement Expression" I concatenate two strings and print the result using "Additional Results"
    2. For verification I display it using "Message Popup" step type. The formatting is as desired in "Message Popup". However, the new line characters appear as "Spaces" in XML report.
    Tracing Of this Erratic Behavior:
    1. I passed the concatenated string to LabVIEW VI and passed it to "Step.Result.ReportText" variable to log it in XML report. The same string which didn't appeared properly using “Additional Results"of "Statement Expression” step now appears proper in XML report.
    I have attached the sequence file for reference. Ensure that Report option is set to XML before executing this sequence.
    Can anyone justify this behavior and suggest the correct approach??
    Thanks !
    Attachments:
    Erratic Behavior Of Additional Results.seq ‏8 KB
    Tracing Of Erratic Behavior.vi ‏9 KB

    Amit -
    Here is a modified version of the TestStand 2010 Horizontal.xsl style sheet that corrects the issue you have mentioned. Note that leading and trailing "\n" characters will still be stripped out, and all "\r" characters will be stripped out.
    Hope this helps.
    Manooch H.
    National Instruments
    Attachments:
    horizontal_modified.zip ‏22 KB

  • Given a multi-line string I want to append a string constant to the beginning of each line.

    Thankyou.

    You could just use "search and replace" with the search string being "\n" (in \codes display) and the replace string as "constant\n". (See attached image).
    If the string you want at the beginning of each line is variable (e.g. line number), you should use e.g. "pick line" or "scan strings for tokens" in a loop, then rebuild the new string.
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    AppendConstant.gif ‏9 KB

  • Multi line strings - line continuation chars?

    Hi all,
    I'm not sure if this is a daft question or not...
    I need to put a multiline select statement into a string variable.
    ie I would like to put the sql below into a variable.
    select bla bla bla bla bla
    from bla
    where bla
    strvar := 'select bla bla bla bla bla
    from bla
    where bla';
    Is there a standard line continuation character that I can put at the end of each line to enable me to put the single quote and the beginning of line 1 and the end of line 3? Or do I need to quote each line front and back and cat them together as separate strings?
    rgds
    John

    Hi John,
    See if this can help you
    declare str varchar2(10000);
    begin
    str := 'select bla bla bla bla bla '||chr(10);
    str := str||'from bla '||chr(10);
    str := str||'where bla '||chr(10);
    dbms_output.put_line(str);
    end;
    SQL> /
    the output should be like below :
    select bla bla bla bla bla
    from bla
    where bla
    Anyway new line character is chr(10) for SQL.
    Thanks
    Kailash K Agarwalla,
    Delhi, India.

  • Need help - ResourceBundle - formated string value (and multi-line string)

    Hi
    Can I put a value for key on many rows and formatted??
    Ex.: Into a file properties can I put
    key =
    My
    name
    is
    JTonic
    When I try to get the value for key, I get "". Can I get "My name is JToniC" ???
    Thx in advance.

    http://java.sun.com/j2se/1.4.2/docs/api/java/util/Properties.html#load(java.io.InputStream)
    The logical line holding all the data for a key-element pair may be spread out across several adjacent natural lines by escaping the line terminator sequence with a backslash character, \.

  • How to discover multi-line of String that will come Flex by Java?

    Hi all,
    I am programming a little application by using Java and Flex.
    One of the functions that Flex contains will have the responsibility to
    send the TextArea value to Java as parameter.
    But that value could contain multi-lines string. Java recieved successfully but the problem that Java read it as single line.
    so, how can I fix this problem?

    Hi,
    so, is there any solution available right now for my problem.
    A text that will come from TextArea that could contains multi-lines
    will be sent to Java as paramenter.
    How can I distinguish the multi-lines onec I deal with it as String?

  • How to determine the length of a line of text in a multi line text control

    I am working on a simple widget to compare two snippets of text.  The string controls are side by side with a colum of square bools in between
    the two string controls.
    The Bools line up with the lines of text in each string control.  The Bools are used as a quick indicator that at that line point there is a difference
    between the two string controls.
     There is a slider that allows the user to scroll up and down,  the slider scrolls both string controls simutaneously.
    As the string controls are scrolled I will be comparing the left and right lines of text and reflecting the match status in the Bool Colum.
    The reason I need to know the length of the line of text is so each line can be compared against one another.  It is not as simple as counting the
    col width of the string control and parsing the text because if there is a line return the text will word wrap before before it extends all the way accross the string control, which will cause parsing discrepencies.
    Any suggestions on obtaining the multi line string control text character length would be much appreciated.
    Best Regards
    Tim C. 
    1:30 Seconds ARRRGHHH!!!! I want my popcorn NOW! Isn't there anything faster than a microwave!

    Front panel of widget....
    1:30 Seconds ARRRGHHH!!!! I want my popcorn NOW! Isn't there anything faster than a microwave!
    Attachments:
    One.vi ‏27 KB

  • Multi line pattern search with like

    Hi All,
    I am using oracle 9i. I want to search for multi - line pattern.
    for e.g.
    update tablename
    set columnname .
    I used select * from user_source where text like '%update tablename%set columnname%' but this only seem to work if update tablename set columnname is in the same line .
    Thanks.

    Well, no wonder it does not work. USER_SOURCE stores one line of text per row, so column text by definition can not contain multi-line strings . One solution could be analytic function LEAD:
    SQL> create or replace
      2    procedure p1
      3      is
      4      begin
      5          update emp
      6             set ename = ename;
      7  end;
      8  /
    Procedure created.
    SQL> select  distinct name
      2    from  (
      3           select  s.*,
      4                   lead(text) over(partition by name order by line) next_text
      5             from  user_source s
      6          )
      7    where text like '%update emp%'
      8      and next_text like '%set ename%'
      9  /
    NAME
    P1
    SQL> SY.

  • How to Remove the /Div in a Multi-line Field when reporting in Excel, getting

    I am uisng Excel Services to extract data from PS2013.  And the Multi-line text fields include the </Div> syntax.  I have looked at a lot of the links regarding how to do this.  I have even borrowed code that was on someones blog. 
    When I try and use it I get the following message and cannot not seem to resolve it after reading varous links regarding this issue. 
    Any ideas?  As a work around I have created an Excel Macro to remove it, however would like to solve it in the query
    Error Message
    The data types
    Nvarchar and Ntext are incompatible in the add operator
    Here is the syntax
    declare @Headxml nvarchar(350)
    declare @Footxml nvarchar(50)
    set @Headxml = N'<?xml version="1.0"?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd"
    [<!ENTITY  nbsp "&#xA0;"><!ENTITY quot "&#x22;">]><html><body>'
    set @Footxml = N'</body></html>'
    SELECT   ProjectOwner.ProjectUID as [ProjectUID],
    ProjectOwner.ProjectName as [Project Name],
    ProjectOwner.[Project Number] as [ECP#],
    TaskRelated.TaskName as [Task Name],
    MSP_WssRiskToTaskLinks_UserView.RiskID as [Risk ID],
    MSP_WssRiskToTaskLinks_UserView.Title as [Risk Title],
    MSP_WssRiskToTaskLinks_UserView.Status as [Status],   
    MSP_WssRiskToTaskLinks_UserView.AssignedToResource as [Assigned To],
    MSP_WssRiskToTaskLinks_UserView.Owner as [PM], 
    MSP_WssRiskToTaskLinks_UserView.DueDate as [Due Date],  
    MSP_WssRiskToTaskLinks_UserView.Probability as [Probability],
    MSP_WssRiskToTaskLinks_UserView.Impact as [Impact], 
    MSP_WssRiskToTaskLinks_UserView.Exposure as [Exposure],
    MSP_WssRiskToTaskLinks_UserView.Cost as [Cost],
    MSP_WssRiskToTaskLinks_UserView.CostExposure as [Cost Exposure],  
    MSP_WssRiskToTaskLinks_UserView.Category as [Category],
    ISNULL(LTRIM((CONVERT(xml,(@Headxml+MSP_WssRiskToTaskLinks_UserView.[Description]+@Footxml),3)
            .value(N'(/)','nvarchar(4000)'))),'') AS [YourMulti-lineCustomFieldNewName],
    MSP_WssRiskToTaskLinks_UserView.MitigationPlan as [Mitigation Plan],  
    MSP_WssRiskToTaskLinks_UserView.ContingencyPlan as [Contingency Plan],
    MSP_WssRiskToTaskLinks_UserView.TriggerTask as [Trigger Task],
    MSP_WssRiskToTaskLinks_UserView.TriggerDescription as [Trigger Description],
    MSP_WssRiskToTaskLinks_UserView.CreatedDate as [Created Date],
    MSP_WssRiskToTaskLinks_UserView.CreateByResource as [Create By],
    MSP_WssRiskToTaskLinks_UserView.ModifiedByResource as [Modified By],
    MSP_WssRiskToTaskLinks_UserView.ModifiedDate as [Modified],
    TaskRelated.TaskUID as [TaskUID],
    TaskRelated.TaskName as [Task Name],
    TaskRelated.TaskStartDate as [Task Start],
    TaskRelated.TaskFinishDate as [Task Finish] FROM dbo.MSP_WssRiskToTaskLinks_UserView
    LEFT OUTER JOIN dbo.MSP_EpmProject_UserView AS ProjectOwner ON ProjectOwner.ProjectUID = MSP_WssRiskToTaskLinks_UserView.ProjectUID
    LEFT OUTER JOIN dbo.MSP_EpmProject_UserView AS ProjectRelated ON ProjectRelated.ProjectUID = MSP_WssRiskToTaskLinks_UserView.RelatedProjectUID
    LEFT OUTER JOIN dbo.MSP_EpmTask_UserView AS TaskRelated ON TaskRelated.ProjectUID = MSP_WssRiskToTaskLinks_UserView.RelatedProjectUID 
    AND TaskRelated.TaskUID = MSP_WssRiskToTaskLinks_UserView.RelatedTaskUID LEFT JOIN dbo.MSP_WssRelationshipType ON
    MSP_WssRiskToTaskLinks_UserView.RelationshipTypeID = MSP_WssRelationshipType.RelationshipTypeID                
    ORDER BY ProjectOwner.ProjectName ASC,  MSP_WssRiskToTaskLinks_UserView.RiskID
    Andrew Payze

    Hi Andrew,
    We normally create a function to do this. Some examples can be found here:
    http://blog.sqlauthority.com/2007/06/16/sql-server-udf-user-defined-function-to-strip-html-parse-html-no-regular-expression/
    http://lazycoders.blogspot.co.uk/2007/06/stripping-html-from-text-in-sql-server.html
    http://stackoverflow.com/questions/457701/best-way-to-strip-html-tags-from-a-string-in-sql-server
    Paul
    Paul Mather | Twitter |
    http://pwmather.wordpress.com | CPS

  • Use REGEXP_INSTR to find a text string with space(s) in it

    I am trying to use REGEXP_INSTR to find a text string with space(s) in it.
    (This is in a Function.)
    Let's say ParmIn_Look_For has a value of 'black dog'. I want to see if
    ParmIn_Search_This_String has 'black dog' anywhere in it. But it gives an error
    Syntax error on command line.
    If ParmIn_Look_For is just 'black' or 'dog' it works fine.
    Is there some way to put single quotes/double quotes around ParmIn_Look_For so this will
    look for 'black dog' ??
    Also: If I want to use the option of ignoring white space, is the last parm
    'ix' 'i,x' or what ?
    SELECT
    REGEXP_INSTR(ParmIn_Search_This_String,
    '('||ParmIn_Look_For||')+', 1, 1, 0, 'i')
    INTO Position_Found_In_String
    FROM DUAL;
    Thanks, Wayne

    Maybe something like this ?
    test@ORA10G>
    test@ORA10G> with t as (
      2    select 1 as num, 'this sentence has a black dog in it' as str from dual union all
      3    select 2, 'this sentence does not' from dual union all
      4    select 3, 'yet another dog that is black' from dual union all
      5    select 4, 'yet another black dog' from dual union all
      6    select 5, 'black dogs everywhere...' from dual union all
      7    select 6, 'black dog running after me...' from dual union all
      8    select 7, 'i saw a black dog' from dual)
      9  --
    10  select num, str
    11  from t
    12  where regexp_like(str,'black dog');
           NUM STR
             1 this sentence has a black dog in it
             4 yet another black dog
             5 black dogs everywhere...
             6 black dog running after me...
             7 i saw a black dog
    5 rows selected.
    test@ORA10G>
    test@ORA10G>pratz
    Also, 'x' ignores whitespace characters. Link to doc:
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/conditions007.htm#i1048942
    Message was edited by:
    pratz

  • Enter Text in Multi Line TextBox and New Lines

    Hi Guys,
    I have a form that takes a users input and saves to an access
    database.
    The data is in turn drawn by a recordset and displayed on an
    ASP page using VBS.
    The form that takes the info has 1 textbox thats multi line
    and I want it to be a simple input box except when the user adds a
    line break by hitting return I want this to be reflected when the
    record is drawn to the detais page..
    Just now no matter how many times I hit return key when
    typing in the multi line text box and add paragraphs or simple
    sentances they all come out with no line breaks on the page when
    shown???
    Do I have to make my own rich text box editor? or is there
    something Im missing?
    Thanks in advance for any thoughts.
    Tag

    Tag2007 wrote:
    > Thanks Im on the site now and dont see the lite
    version?? Do you have a link to it please..
    InterAKT was acquired by Adobe in September and most of its
    products
    were discontinued. The full version of KTML is now part of
    the
    Kollection suite.
    The solution to your problem is very simple, though. I'm
    sorry I can't
    give you the exact coding, because I haven't used ASP for
    many years.
    However, all that you need to do is to create a function that
    searches a
    string for new line characters and replaces them with
    <br> (or <br />
    for XHTML).
    PHP has a built-in function (nl2br()) to do this, but in ASP
    you need to
    search for the new line character code.
    David Powers, Adobe Community Expert
    Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
    Author, "PHP Solutions" (friends of ED)
    http://foundationphp.com/

  • How to present a Column which includes multi lines

    Hi,
    In Oracle BI Publisher 11g, I'm trying to present a column which includes a long string with <CR>.
    Like an Example:
    abc
    def
    ghi
    But, It presents the all sting in one line like:
    abcdefghi
    How can I present it as its stored in the Database?
    Thanks.
    Edited by: Hadar on Feb 18, 2011 6:55 AM

    Thanks BipUser,
    This is not the same issue.
    I'm Talking about a column which includes multi lines.
    When I select it from SqlPlus:
    Select col1 From Tab1 Where rownum <2;
    I got:
    abc
    def
    ghi
    But, from Bi Publisher I got:
    abcdefghi
    Why? and how Can I Present it as it saved in Database?

Maybe you are looking for