String Match using RegExp

Hi ,
I am new to this:
I have the following requirement :
String1: '1,12,4'
String2: '2'
[both strings could be comma separated]
I need to check if evey member of String2 exists in String1.  I was able to write the PL/SQL code for looping but when i use : select REGEXP_SUBSTR ('1,12,4','2') from dual, I get 2 as the result which is incorrect. Can someone please help me with this ?
Thanks in advance

Hi,
Ssharma21 wrote:
Will there always be exactly 1 string1 and 1 string2, or will you be getting.multiple values (from a table, for example)?
Ans
Both Strings have comma separated values.
Ex: String1 ='1,2,3'
String ='2,3'
Are both strings ordered the same way?  That is, given that '12' comes before '4' in string1, can we be sure that '12' will come before '4' when both appear in string2 ?
Ans
What if there are duplicates in either string?
Ans: No duplicates
I wrote the following piece of code :
BEGIN 
      v_levelIncludedFlag := FALSE;  
      v_tempFlag := TRUE;  
      v_array := APEX_UTIL.string_to_table (v_String2, ',');  
      FOR i IN 1 .. v_array.COUNT 
      LOOP  
         IF REGEXP_SUBSTR (v_String1, v_array (i)) IS NOT NULL 
         THEN 
            v_levelIncludedFlag := TRUE;  
         ELSE 
            v_levelIncludedFlag := FALSE;  
         END IF;  
         v_levelIncludedFlag := v_levelIncludedFlag AND v_tempFlag;  
         v_tempFlag := v_levelIncludedFlag;  
      END LOOP;  
END 
Just the REGEXP_SUBSTR is not giving me the correct result due when String1='12' and String2='2' . I should be getting NULL from REGEXP_SUBSTR (v_String1, v_array (i))
The 1
st question is: Will you be comparing exactly 1 comma-delimited string against exactly 1 comma-delimited string?
It looks like you forgot to post the answer to the 2nd question.
Depending on your answers, you might want something like this:
VARIABLE  string1  VARCHAR2 (100)
VARIABLE  string2  VARCHAR2 (100)
EXEC  :string1 := '1,12,4';
EXEC  :string2 := '12,1';
WITH s1 AS
    SELECT  REGEXP_SUBSTR ( :string1
                          , '[^,]+'
                          , 1
                          , LEVEL
                          ) AS item
    FROM    dual
    CONNECT BY  LEVEL  <= REGEXP_COUNT (:string1, '[^,]+')
, s2 AS
    SELECT  REGEXP_SUBSTR ( :string2
                          , '[^,]+'
                          , 1
                          , LEVEL
                          ) AS item
    FROM    dual
    CONNECT BY  LEVEL  <= REGEXP_COUNT (:string1, '[^,]+')
SELECT    CASE
              WHEN  COUNT (s2.item) = 0
              THEN  'Everything in ' || :string2 || ' is also in '      || :string1
              ELSE  'Something in '  || :string2 || ' is missing from ' || :string1
          END   AS output
FROM          s2
LEFT OUTER JOIN  s1  ON  s1.item = s2.item
WHERE      s1.item  IS NULL
Whatever your requirements are, you probably don't need PL/SQL, though you may want to use PL/SQL for several reasons.

Similar Messages

  • How can I return all line in a file that matches using regexp

    Hi!
    I want to return whole line from a file. This lines must to contains matches for a pattern.
    How Can I do this.
    I make some samples, but only return the matches segment of the line.
    Sample code to look for 00:00
    If I put .*00:00.* in the pattern this return whole line, but is to slow in this file about 300,000 lines.
    If I put just 00:00 in the pattern only return the 00:00, but so fast.
    What can I Do, or I must use indexOf in a sequential read?
              try {
                   // Create matcher on file
                   Pattern pattern = Pattern.compile(".*00:00.*");
                   Matcher matcher = pattern.matcher(fromFile("logusers_0712"));
                   // Find all matches
                   while (matcher.find()) {
                        // Get the matching string
                        String match = matcher.group();
                                     //Here I display the matches
                        System.out.println(match);
              } catch (IOException e) {
                   e.printStackTrace();
              }Thanks in advance

    My two cents:
    Grep is a Bad Idea (TM). It is not java and itties
    es the solution to a the operational system.Not necessarily bad. Like you say--we don't know much
    about the OP's requirements, so grep may be just
    fine.
    !java != badYour assertion is true. But creating an solution tied to the system when you can do it pure java does not seem like a good Idea especially when we not even know which system he is using. What if he is using Windows or MacOS? Sure he can use grep on non *nix systems, but that would fore him to install the necessary tools, making his solution even more complex.
    >
    About using indexOf, it is a little limited, not
    ot knowing what exactly the OP is searching for itis
    difficult to say if it is enough. RegEx would workin
    both ways.He said he was searching for "00:00". I think that was just a sample. He apears to be scanning a log file as far as I understood. 00:00 could be a timestamp for whose he wants to see the entries. Using a RegEx make the job easier, like "01:\\d{2} am" to get the whole range of entries inside that morning hour.
    If it's really
    that literal string he needs to match, as opposed to
    say "\\d\\d:\\d\\d" then indexOf is simpler. It will
    probably perform better too. I don't know if that
    difference will be significant, but on a file of
    300,000 lines, it might be noticable.The only way to know that is testing both solutions. But you are right, we are just wondering here, with no better info on the requirements anything can go. I agree with you, indexOf is the simple way to go and probably will sufice.
    May the code be with you.

  • Advanced String Manipulation Using REGEXP

    Hello all,
    I've been trying to split a string using either REGEXP_SUBSTR and REGEXP_REPLACE functions with much success so I wonder whether anyone here can give me a hand. Basically the string I want to split in to 3 is in this format:
    'instanceno;partno;serialno'
    I have read numerous articles within last few days but I still can't get it to working (I'm sure due to my lack of regular expression handling knowledge in OBIEE). I found two articles discussing similar scenarios. One in here and the other one is here. Both of those are good, but I cannot apply those principles to my query as I'm keep getting issues with the use of semicolon (;).
    Could someone explain to me how to split this string so I can have 3 separate columns, please?
    Thanks and regards,

    Hi Anuhas,
    you have to create 3 columns in the report on 3 attribute columns inside le Logical Model with this syntax for the the string str = 'instanceno;partno;serialno'
    COLUMN1 = evaluate('regexp_substr(%1,''[^\;]+'', 1,1)',REPLACE(*str*,';','\;'))
    COLUMN2 = evaluate('regexp_substr(%1,''[^\;]+'', 1,2)',REPLACE(*str*,';','\;'))
    COLUMN3 = evaluate('regexp_substr(%1,''[^\;]+'', 1,3)',REPLACE(*str*,';','\;'))
    You have to use the REPLACE function (; --> \;) because the ; is e special character
    In this way you have:
    COLUMN1 = instanceno
    COLUMN2 = partno
    COLUMN3 = serialno
    The regex_substr(a,b,c) contains:
    a = str the string
    b = [^\;]+ find for the beginning of the string the character ;
    c = number of occurrence
    I hope it hepls.
    Regards,
    Gianluca

  • The case structure is not working well on comaring two strings using true or false string matching VI

    I need an execution of commands after the reply from the instrument matches with the string I provided for that i used true or false string match VI on which the true string the matching command and the string is the reply from the instrument. And I put the further executionable commands in frame after frame of sequence loop in the true of the case structure. Amd finally I given all the output strings to the concatenate string to get all the replies as one loop. But when I execute the program the desired result is not available. So kindly please help me to overcome this problem.  
    Attachments:
    basic serial with changes.vi ‏24 KB

    You VI makes absolutely no sense and I would recommend you start with a few simple LabVIEW tutorials before trying to tackle this.
    What is the point of the FOR loop with 1 iteration, it might as well not even be there, same difference.
    Why is there an abort primitive in the FOR loop, this mean the program will unconditionally stop abort before any downstream code will ever go into action. The program will never get past the FOR loop.
    You created a circular data dependency and LabVIEW inserted a feedback node automatically, making things even worse. (see also)
    You need to learn about dataflow, execution order, and data dependency.
    You need to learn about the various types of tunnels (plain, autoindexing, etc.)
    There is a tremendous amount of duplicate code. Large code sections are the same, differeing only by a string. You should only have one copy of that code inside a proper state machine. Have a look at the design templates and examples that ship with LabVIEW.
    LabVIEW Champion . Do more with less code and in less time .

  • String replace All using RegExp

    var myString:String="<font face='arial' size='14'>ZX</font><span class='cssid'>some Text </span><font face='arial' size='14'>USP</font>"
      var fontName:String="Vardana"
    var fontSize:String="11"
      var regexp:RegExp = /<font.*?>/;
      myString = myString.replace(regexp, "<font face='"+fontName+"' size='"+fontSize+"' >");
    above scripte replacing only "<font face='arial' size='14'>ZX</font>"
    i need to replace   : "<font face='arial' size='14'>ZX</font><span class='cssid'>some Text </span><font face='arial' size='14'>USP</font>"

    var regexp:RegExp = /<font.*?>/igm;

  • 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

  • Java Regex - Find Last Match Using Pattern and Matcher

    I'd like to write some regex which would allow me to grab the last occurance of match based on a specified list of items. So for:
    Pattern languageRegex = Pattern.compile("(len|end)");
    And a string of:
    "00| 0lend|"
    I want it to extract "end". However, I'd grab "len" using the above regex.
    If it was
    "00| 0lenend|"
    I'd grab "end" which is right.
    What regex would allow me to grab "end" rather than "len" from:
    "00| 0lend|"
    Thanks for your help.

    user3940995 wrote:
    I have a list of 3 letter codes that I need to check for in a field. The list is finite but about 100 or so items:
    len, end, ren, onm, enl, etc.
    However, the field I'm checking in has some other data in it which can bleed into the code but the code will always be at the end.
    An example would be "000 0rend"
    From this I'd want to extract "end". If there is a better way to do this than using regex then I'd be happy to use that, but as I have to process millions of items I'm keen to not loop trying to find a match so I was hoping there would be a regex solution.
    Your regex would work for that particular example. I think if I modify it to be
    Pattern.compile("len(?!\\D)|end(?!\\D)|enl(?!\\D)"); (which would then be extended for all the list items)
    Then I seem to pick up the last occurance as I'd like to.
    Thank you for your help!Doesn't sound like you want to use regexp. I would instead build a character graph/tree with my commands in reversed order. I would then search each line backwards and check if it matches something in my tree.

  • String.matches() faulty?

    I wondered why my regExp didn't work when I called it with
    myString.matches(searchString);So I wrote this test code:
            System.out.println("Test: if substring exists:");
            String text = "Using org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser as SAX2 Parser";
            String search = "as SAX2 Parser";
            String regExp = "\\S*("+search.toUpperCase()+"\\S*)";
            Pattern pat = Pattern.compile(regExp);
            Matcher m = pat.matcher(text.toUpperCase());
            while (m.find()) {
                System.out.println("found2: "+text.substring(m.start(), m.end()));
            System.out.println("Same with String.matches:");
            System.out.println("found2: "+text.matches(regExp));and the first custom code matches the regExp and the String.matches() doesn't match. What's the catch?

    "abc" -> find ("b") -> finds "b"
    "abc".matches("b") -> returns false
    "b".matches("b") -> returns false
    "abc".matches(".b.") > returns trueIf you'd like you could say that matches assumes an
    implicit "^" at the beginning and an "$" at the end
    of your regex. It tries to match the entire
    string and if it doesn't capture it all it returns
    false.Why is
    "b".matches("b") -> returns false?

  • Email Regular Expression with a String.Match()

    I'm currently using a RichTextEditor for a user to build HTML
    for a site. However, I want the application to scan for emails and
    encode them so they are protected from spam bots when they go to
    the live site. I've written a regular expression to find an email
    and it seems to work, but it only returns one email at a time from
    the string. I have had to revert to a while loop to traverse the
    string until I'm satisfied. I don't particularly like that method
    and would like to just do one String.match() query to retrieve all
    of the emails. Can anyone see something here that I'm missing?

    Try adding the global flag (g):
    var emailPattern:RegExp =
    /[a-z][\w.-]+@\w[\w.-]+\.[\w.-]*[a-z][a-z]+/g;
    TS

  • Trying to compare string array using equals not working

    Hi,
    im prolly being really dumb here, but i am trying to compare 2 string arrays using the following code:
    if(array.equals(copymearray))
    System.out.println("they match");
    else
    {System.out.println("dont match");}
    the trouble is that even though they do match i keep getting dont match, can anyone tell me why?

    try
    if (Arrays.equals(array, copymearray))
    System.out.println("they match");
    else
    {System.out.println("dont match");}

  • How to use RegExp in Flash Forms

    Hello searching for help by ActionScript StringFunction
    try to do var res = string.match('^(2..)$')
    allways get an undefined for 'res'
    Anyone got an Idee ??

    > CF response
    You said you needed help with ActionScript. What I gave you
    is ActionScript.
    Coldfusion has no built-in method called
    match. You should use REMatch(reg_expression, string) or
    REMatchNoCase(reg_expression, string), assuming you're on CF 8, of
    course.

  • Converting Oracle XML Query Result in Java String by using XSU

    Hi,
    I have a problem by converting Oracle XML Query Result in Java
    String by using XSU. I use XSU for Java.
    For example:
    String datum=new OracleXMLQuery(conn,"Select max(ps.datum) from
    preise ps where match='"+args[0]+"'");
    String datum1=datum;
    I become the following error:
    Prototyp.java:47: Incompatible type for declaration. Can't
    convert oracle.xml.sql.query.OracleXMLQuery to java.lang.String.
    Can somebody tell me a method() for converting to solve my
    problem??????
    Thanks

    Hmmm.. Pretty basic just look at the example:
    OracleXMLQuery qry = new OracleXMLQuery(conn,"Select max(ps.datum) from preise ps where match='"+args[0]+"'");
    String xmlString = qry.getXMLString();
    Hi,
    I have a problem by converting Oracle XML Query Result in Java
    String by using XSU. I use XSU for Java.
    For example:
    String datum=new OracleXMLQuery(conn,"Select max(ps.datum) from
    preise ps where match='"+args[0]+"'");
    String datum1=datum;
    I become the following error:
    Prototyp.java:47: Incompatible type for declaration. Can't
    convert oracle.xml.sql.query.OracleXMLQuery to java.lang.String.
    Can somebody tell me a method() for converting to solve my
    problem??????
    Thanks

  • Parse a string that uses nested string delimiters

    I’m looking for a way to parse a string that uses double quotes as the delimiter that contains a nested string with double quotes.  I want to keep the double quotes in the nested string.  Is there a function in Labview that I can use to easily do this?  Does Labview have a command line parser / interpreter?
    The string example is: While match "Send Test "Sleep 5" ">""
    The result string would be:  Send Test "Sleep 5" ">"

    Here is another solution which is slightly faster.  Speed won't be
    an issue unless you are running millions at a time, as in my test the
    difference was only 1-2 ms in 10000 iterations.  In this image the
    Match Pattern function retrieves the desired string, including the
    outside quotes, so the String Length and String Subset functions are
    used to remove the first and last characters of the result.
    Message Edited by tuba on 04-11-2006 10:35 PM
    Attachments:
    parse.gif ‏3 KB

  • Regular expressions and string matching

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

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

  • An additional question about regular expressions with String.matches

    does the String.matches() method match expressions when some substring of the String matches, or does it have to match the entire String? So, if i have the String "123ABC", and i ask to match "1 or more letters" will it fail because there are non-letters in the String, but then pass if i add "1 or more letters AND 1 or more digits"? so, in the latter every character in the String is accounted for in the search, as opposed to the first. Is that correct, or are there ways to JUST match some substring in the String instead of the whole thing? i WILL make some examples too... but does that make sense?

    It has to match the whole String. Use Matcher.find() to match on just a sub-string()

Maybe you are looking for