ANN: New Regular Expressions Sample

Hi,
Regular expressions introduced in Oracle 10g Database is one of the most powerful ways of searching, manipulating and transforming text data.
Check out this new [url http://www.oracle.com/technology/sample_code/tech/pl_sql/regexp/dnasample/readme.html]DNA Analysis Sample, that uses the regular expression APIs to identify certain enzyme patterns in a DNA Sequence.
Also visit the [url http://www.oracle.com/technology/sample_code/tech/pl_sql/index.html]PL/SQL Sample Code page for more samples on PL/SQL.
Thanks
Shrinivas
OTN Team

This bunch of samples does not currently have one. We will look at it.
Cheers,
-- Rajesh

Similar Messages

  • Using regular expressions for validating time fields

    Similar to my problem with converting a big chunk of validation into smaller chunks of functions I am trying to use Regular Expressions to handle the validation of many, many time fields in a flexible working time sheet.
    I have a set of FormCalc scripts to calculate the various values for days, hours and the gain/loss of hours over a four week period. For these scripts to work the time format must be in HH:MM.
    Accessibility guidelines nix any use of message box pop ups so I wanted to get around this by having a hidden/visible field with warning text but can't get it to work.
    So far I have:
    var r = new RegExp(); // Create a new Regular Expression Object
    r.compile ("^[00-99]:\\] + [00-59]");
    var result = r.test(this.rawValue);
    if (result == true){
    true;
    form1.flow.page.parent.part2.part2body.errorMessage.presence = "visible";
    else (result == false){
    false;
    form1.flow.page.parent.part2.part2body.errorMessage.presence = "hidden";
    Any help would be appreciated!

    Date and time fields are tricky because you have to consider the formattedValue versus the rawValue. If I am going to use regular expressions to do validation I find it easier to make them text fields and ignore the time patterns (formattedValue). Something like this works (as far as my very brief testing goes) for 24 hour time where time format is HH:MM.
    // form1.page1.subform1.time_::exit - (JavaScript, client)
    var error = false;
    form1.page1.subform1.errorMsg.rawValue = "";
    if (!(this.isNull)) {
      var time_ = this.rawValue;
      if (time_.length != 5) {
        error = true;
      else {
        var regExp = /^([01]?[0-9]|2[0-3]):[0-5][0-9]$/;
        if (!(regExp.test(time_))) {
          error = true;
    if (error == true) {
      form1.page1.subform1.errorMsg.rawValue = "The time must be in the format HH:MM where HH is 00-23 and MM is 00-59.";
      form1.page1.subform1.errorMsg.presence = "visible";
    Steve

  • How to find Regular Expressions in a Hash Map

    Hi,
    I Have a hash map with some keys. The Keys are like this(Java.util.regex, Javax.swing.table, javax.swing.text, Java.util.jar, Java.text etc). Suppose if the user gives the search pattern as "text", the o/p should be javax.swing.text and java.text.. How to do it using regular Expressions

    // Sample code...
    import java.util.regex.*;
    public class TestRegex {
        public static void main(String[] args) {
            String test1 = "java.util.regex";
            String test2 = "javax.swing.text";
            String test3 = "java.util.jar";
            String test4 = "java.text";
            Pattern pat = Pattern.compile(".*text.*");
            Matcher mt1 = pat.matcher(test1);
            System.out.println("1> " +mt1.matches());
            Matcher mt2 = pat.matcher(test2);
            System.out.println("2> " +mt2.matches());
            Matcher mt3 = pat.matcher(test3);
            System.out.println("3> " +mt3.matches());
            Matcher mt4 = pat.matcher(test4);
            System.out.println("4> " +mt4.matches());
    }

  • Regular Expression - Extract words before the PLUS Sign ?

    Dear All,
    I had many words with having a symbol plus. I need to extract the words before the plus sign.
    I can able to do this by using String.indexOf or String.contains. But i like to know is there is any way to do this using Regular Expression.
    sample string
    Kathire+san Output Kathire
    World+islike Output World
    Thanks,
    J.Kathir

    Here's one way.
    import java.util.regex.Pattern;
    String input = "abc+def";
    Pattern pat = pat.compile("\\+");
    String beforePlus = pat.split(input)[0];
    Sun's Regular Expression Tutorial for Java
    Regular-Expressions.info

  • Regular expression- insert into a string phrase "new" into correct position

    I have sample data in table T below, and i have sample output how i want the query to output over that data.
    with T as
    select 'CREATE OR REPLACE PACKAGE BODY "YYY"."PACKAGEONE" IS' s from dual union all
    select 'Create or REPLACE PACKAGE BODY "ZZZ"."PACKAGETWO" IS' s from dual
    select REGEXP_REPLACE(T.s, '^.PACKAGE BODY$','(\1)_new',1,1,'i') as s from T;
    Expected output:
    CREATE OR REPLACE PACKAGE BODY "YYY"."PACKAGEONE_new" IS
    Create OR REPLACE PACKAGE BODY "ZZZ"."PACKAGETWO_new" IS
    */All data has following pattern:
    CREATE OR REPLACE PACKAGE BODY "[owner]"."[name]" ISWhere [owner] can be any string. In sample data we have for example values XXX and YYY there.
    And [name] can be any string. In sample data we have for example values PACKAGEONE and PACKAGETWO there.
    Other parts of the string is fixed and stays as you see.
    As shown in expected output query should replace substring "[owner]"."[name]" to "[owner]"."[name]_new"
    How can i write such query?
    I think i somehow should in regular expression count the positions of double quotes to achieve the expected result, but i don't know how.

    Thx, but your solution doesn't work, it doesn't put phrase "new" into string. I use Oracle 10g.
    with T as
    select 'CREATE OR REPLACE PACKAGE BODY "YYY"."PACKAGEONE" IS...' s from dual union all
    select '...Create or REPLACE PACKAGE BODY "ZZZ"."PACKAGETWO" ..."a"."b" procedure a IS..' s from dual
    select
    RegExp_Replace(s,'(" IS$)','_new\1') as new
    from t;
    CREATE OR REPLACE PACKAGE BODY "YYY"."PACKAGEONE" IS...
    ...Create or REPLACE PACKAGE BODY "ZZZ"."PACKAGETWO" ..."a"."b" procedure a IS..
    {code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Regular Expressions in the new editor

    Hi,
    we just ubgraded to SAP GUI 6.40 and ERP 2005, when i hit ctrl-h the search and replace dialog is popping up in the new editor. But the checkbox "regular expression" is greyed out and cant be activated. Why?
    cu
    Rainer

    Hi, I can only confirm that. The help indicates that it should work, but on the screencaps, it's grayed out too.
    Besides that,
    Open completion automatically after is not implemented yet (is mentioned in the help).
    There are also problems with the incremental search backwards. It works only once.
    Eddy
    PS.
    Put yourself on the SDN world map (http://sdn.idizaai.be/sdn_world/sdn_world.html) and earn 25 points.
    Spread the wor(l)d!

  • Regarding Line Break Expression (New to Regular Expression)

    Hi,
    I am new to regular expression.
    I have a query.Suppose I have a
    String str = Anshuk
    Anshuk1
    Anshuk2
    Anshuk3
    Anshuk4
    where we have a line break after Anshuk and then again after Anshuk1 and so on.Actually, we have different records in different lines.
    how do I make it possible usign regex that to make him inderastand that those are in different lines (meaning different records)?
    I m trying...but not getting it..wat should be the code?
    anshuk

    What do you mean? What have you done?
    Have you set the pattern to use MULTILINE?
    Kaj

  • New Airport Express and airplay of 96 kHz sample rate

    Does the new Airport Express (released this week) support airplay of 96 kHz sample rate music?  I'm not sure what part of the old version's architecture was limited to 16/44.1, but am hoping with the newer version they have removed this limitation.  The tech specs don't mention specifics about audio resolution.  Anyone know?

    Unfortunately, the new airport express is still limited to 44.1 kHz for bitperfect AirPlay.
    Come on!  The Logitech Squeezebox needs a competitor.

  • Help in regular expression matching

    I have three expressions like
    1) [(y2009)(y2011)]
    2) [(y2008M5)(y2011M3)] or [(y2009M5)(y2010M12)]
    3) [(y2009M1d20)(y2011M12d31)]
    i want regular expression pattern for the above three expressions
    I am using :
    REGEXP_LIKE(timedomainexpression, '???[:digit:]{4}*[:digit:]{1,2}???[:digit:]{4}*[:digit:]{1,2}??', 'i');
    but its giving results for all above expressions while i want different expression for each.
    i hav used * after [:digit:]{4}, when i am using ? or . then its giving no results. Please help in this situation ASAP.
    Thanks

    I dont get your question Can you post your desired output? and also give some sample data.
    Please consider the following when you post a question.
    1. New features keep coming in every oracle version so please provide Your Oracle DB Version to get the best possible answer.
    You can use the following query and do a copy past of the output.
    select * from v$version 2. This forum has a very good Search Feature. Please use that before posting your question. Because for most of the questions
    that are asked the answer is already there.
    3. We dont know your DB structure or How your Data is. So you need to let us know. The best way would be to give some sample data like this.
    I have the following table called sales
    with sales
    as
          select 1 sales_id, 1 prod_id, 1001 inv_num, 120 qty from dual
          union all
          select 2 sales_id, 1 prod_id, 1002 inv_num, 25 qty from dual
    select *
      from sales 4. Rather than telling what you want in words its more easier when you give your expected output.
    For example in the above sales table, I want to know the total quantity and number of invoice for each product.
    The output should look like this
    Prod_id   sum_qty   count_inv
    1         145       2 5. When ever you get an error message post the entire error message. With the Error Number, The message and the Line number.
    6. Next thing is a very important thing to remember. Please post only well formatted code. Unformatted code is very hard to read.
    Your code format gets lost when you post it in the Oracle Forum. So in order to preserve it you need to
    use the {noformat}{noformat} tags.
    The usage of the tag is like this.
    <place your code here>\
    7. If you are posting a *Performance Related Question*. Please read
       {thread:id=501834} and {thread:id=863295}.
       Following those guide will be very helpful.
    8. Please keep in mind that this is a public forum. Here No question is URGENT.
       So use of words like *URGENT* or *ASAP* (As Soon As Possible) are considered to be rude.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Help regarding regular expression

    HI All ,
    Please see the following string
    String s = "IF ((NOT NUM4 IS ALPHABETIC ) AND NUM3 IS ALPHABETIC-UPPER AND (NUM5 IS GREATER OR EQUAL TO 3) AND (NUM5 IS NOT GREATER THAN 3) AND (NUM3 GREATER THAN 46) AND (NUM5 GREATER THAN NUM3) OR NUM3 LESS THAN 78) .";
    My problem is: i want to capture the part of this line which contains "ALPHABETIC ,ALPHABETIC-UPPER for ex :NOT NUM4 IS ALPHABETIC , NUM3 IS ALPHABETIC-UPPER.from that I have to capture the word num4 , num3 which are in these phrases only ;from the whole string whereever it exists along with the phrase,Can any one help me out by suggesting something.num4 and num3 are variable names

    I suspect you're right, Sabre, but I can't resist...
    import java.util.regex.*;
    * A rewriter does a global substitution in the strings passed to its
    * 'rewrite' method. It uses the pattern supplied to its constructor, and is
    * like 'String.replaceAll' except for the fact that its replacement strings
    * are generated by invoking a method you write, rather than from another
    * string. This class is supposed to be equivalent to Ruby's 'gsub' when given
    * a block. This is the nicest syntax I've managed to come up with in Java so
    * far. It's not too bad, and might actually be preferable if you want to do
    * the same rewriting to a number of strings in the same method or class. See
    * the example 'main' for a sample of how to use this class.
    * @author Elliott Hughes
    public abstract class Rewriter
      private Pattern pattern;
      private Matcher matcher;
       * Constructs a rewriter using the given regular expression; the syntax is
       * the same as for 'Pattern.compile'.
      public Rewriter(String regularExpression)
        this.pattern = Pattern.compile(regularExpression);
       * Returns the input subsequence captured by the given group during the
       * previous match operation.
      public String group(int i)
        return matcher.group(i);
       * Overridden to compute a replacement for each match. Use the method
       * 'group' to access the captured groups.
      public abstract String replacement();
       * Returns the result of rewriting 'original' by invoking the method
       * 'replacement' for each match of the regular expression supplied to the
       * constructor.
      public String rewrite(CharSequence original)
        this.matcher = pattern.matcher(original);
        StringBuffer result = new StringBuffer(original.length());
        while (matcher.find())
          matcher.appendReplacement(result, "");
          result.append(replacement());
        matcher.appendTail(result);
        return result.toString();
      public static void main(String[] args)
        String s = "IF ((NOT NUM4 IS ALPHABETIC ) " +
                    "AND NUM3 IS ALPHABETIC-UPPER " +
                    "AND (NUM5 IS GREATER  OR EQUAL TO 3) " +
                    "AND (NUM5 IS NOT GREATER THAN 3) " +
                    "AND (NUM3 GREATER THAN 46) " +
                    "AND NUM645 IS ALPHABETIC " +
                    "AND (NUM5 GREATER THAN NUM3) " +
                    "OR NUM3 LESS THAN 78 " +
                    "AND NUM34 IS ALPHABETIC-UPPER " +
                    "AND NUM92 IS ALPHABETIC-LOWER " +
                    "AND NUM0987 IS ALPHABETIC-LOWER) .";
        String result =
          new Rewriter("(NUM\\d+) +IS +(ALPHABETIC(?:-(?:UPPER|LOWER))?)")
            public String replacement()
              String type = group(2);
              if (type.endsWith("UPPER"))
                return "Character.isUpper(" + group(1) + ")";
              else if (type.endsWith("LOWER"))
                return "Character.isLower(" + group(1) + ")";
              else
                return "Character.isLetter(" + group(1) + ")";
          }.rewrite(s);
        System.out.println(result);
    }

  • Java – Regular Expressions – Finding any non digit byte in a multiple byte

    Hello,
    I’m new to JAVA and Regular Expressions; I’m trying to write a regular expression that will find any records that contain a non digit byte in a multiple byte field.
    I thought the following was the correct expression but it is only finding records that contain “all” non digit bytes.
    \D{1,}
    \D = Non Digit
    {1,} = at least 1 or more
    Below is my sample data. I would like the regular expression to find all of the records that are not all numeric. However when I use the regular expression \D{1,} it is only finding the 2 records that all bytes are non digits. (i.e. “ “ and “A “)
    “ 111229”
    “2 111229”
    “20091229”
    “200912c9”
    “201#1229”
    “20101229”
    “20110229”
    “20111*29”
    “20111029”
    “20111229”
    “20B11229”
    “A “
    “A0111229”
    Please note I have also tried \D{1,}+ and \D{1,}? And they also do not return my desired results
    Any assistance someone can provide would be greatly appreciated.

    You don't show the code you are using but I surmise you are using String.matches() which requires that the whole target must match the regular expression not just part of it. Instead you should create a Pattern and then a Matcher and use the Matcher.find() method. Check the Javadoc for Pattern and Matcher and look at the Java regex tutorial - http://docs.oracle.com/javase/tutorial/essential/regex/ .
    P.S. You can re-use the Pattern object - you don't have to create it every time you need one.
    P.P.S. Java regular expressions work with characters not bytes and characters are not not not bytes.

  • Introduction to regular expressions ... last part.

    Continued from Introduction to regular expressions ... continued., here's the third and final part of my introduction to regular expressions. As always, if you find mistakes or have examples that you think could be solved through regular expressions, please post them.
    Having fun with regular expressions - Part 3
    In some cases, I may have to search for different values in the same column. If the searched values are fixed, I can use the logical OR operator or the IN clause, like in this example (using my brute force data generator from part 2):
    SELECT data
      FROM TABLE(regex_utils.gen_data('abcxyz012', 4))
    WHERE data IN ('abc', 'xyz', '012');There are of course some workarounds as presented in this asktom thread but for a quick solution, there's of course an alternative approach available. Remember the "|" pipe symbol as OR operator inside regular expressions? Take a look at this:
    SELECT data
      FROM TABLE(regex_utils.gen_data('abcxyz012', 4))
    WHERE REGEXP_LIKE(data, '^(abc|xyz|012)$')
    ;I can even use strings composed of values like 'abc, xyz ,  012' by simply using another regular expression to replace "," and spaces with the "|" pipe symbol. After reading part 1 and 2 that shouldn't be too hard, right? Here's my "thinking in regular expression": Replace every "," and 0 or more leading/trailing spaces.
    Ready to try your own solution?
    Does it look like this?
    SELECT data
      FROM TABLE(regex_utils.gen_data('abcxyz012', 4))
    WHERE REGEXP_LIKE(data, '^(' || REGEXP_REPLACE('abc, xyz ,  012', ' *, *', '|') || ')$')
    ;If I wouldn't use the "^" and "$" metacharacter, this SELECT would search for any occurence inside the data column, which could be useful if I wanted to combine LIKE and IN clause. Take a look at this example where I'm looking for 'abc%', 'xyz%' or '012%' and adding a case insensitive match parameter to it:
    SELECT data
      FROM TABLE(regex_utils.gen_data('abcxyz012', 4))
    WHERE REGEXP_LIKE(data, '^(abc|xyz|012)', 'i')
    ; An equivalent non regular expression solution would have to look like this, not mentioning other options with adding an extra "," and using the INSTR function:
    SELECT data
      FROM (SELECT data, LOWER(DATA) search
              FROM TABLE(regex_utils.gen_data('abcxyz012', 4))
    WHERE search LIKE 'abc%'
        OR search LIKE 'xyz%'
        OR search LIKE '012%'
    SELECT data
      FROM (SELECT data, SUBSTR(LOWER(DATA), 1, 3) search
              FROM TABLE(regex_utils.gen_data('abcxyz012', 4))
    WHERE search IN ('abc', 'xyz', '012')
    ;  I'll leave it to your imagination how a complete non regular example with 'abc, xyz ,  012' as search condition would look like.
    As mentioned in the first part, regular expressions are not very good at formatting, except for some selected examples, such as phone numbers, which in my demonstration, have different formats. Using regular expressions, I can change them to a uniform representation:
    WITH t AS (SELECT '123-4567' phone
                 FROM dual
                UNION
               SELECT '01 345678'
                 FROM dual
                UNION
               SELECT '7 87 8787'
                 FROM dual
    SELECT t.phone, REGEXP_REPLACE(REGEXP_REPLACE(phone, '[^0-9]'), '(.{3})(.*)', '(\1)-\2')
      FROM t
    ;First, all non digit characters are beeing filtered, afterwards the remaining string is put into a "(xxx)-xxxx" format, but not cutting off any phone numbers that have more than 7 digits. Using such a conversion could also be used to check the validity of entered data, and updating the value with a uniform format afterwards.
    Thinking about it, why not use regular expressions to check other values about their formats? How about an IP4 address? I'll do this step by step, using 127.0.0.1 as the final test case.
    First I want to make sure, that each of the 4 parts of an IP address remains in the range between 0-255. Regular expressions are good at string matching but they don't allow any numeric comparisons. What valid strings do I have to take into consideration?
    Single digit values: 0-9
    Double digit values: 00-99
    Triple digit values: 000-199, 200-255 (this one will be the trickiest part)
    So far, I will have to use the "|" pipe operator to match all of the allowed combinations. I'll use my brute force generator to check if my solution works for a single value:
    SELECT data
      FROM TABLE(regex_utils.gen_data('0123456789', 3))
    WHERE REGEXP_LIKE(data, '^(25[0-5]|2[0-4][0-9]|[01]?[0-9]{1,2})$') 
    ; More than 255 records? Leading zeros are allowed, but checking on all the records, there's no value above 255. First step accomplished. The second part is to make sure, that there are 4 such values, delimited by a "." dot. So I have to check for 0-255 plus a dot 3 times and then check for another 0-255 value. Doesn't sound to complicated, does it?
    Using first my brute force generator, I'll check if I've missed any possible combination:
    SELECT data
      FROM TABLE(regex_utils.gen_data('03.', 15))
    WHERE REGEXP_LIKE(data,
                       '^((25[0-5]|2[0-4][0-9]|[01]?[0-9]{1,2})\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9]{1,2})$'
    ;  Looks good to me. Let's check on some sample data:
    WITH t AS (SELECT '127.0.0.1' ip
                 FROM dual
                UNION 
               SELECT '256.128.64.32'
                 FROM dual            
    SELECT t.ip
      FROM t WHERE REGEXP_LIKE(t.ip,
                       '^((25[0-5]|2[0-4][0-9]|[01]?[0-9]{1,2})\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9]{1,2})$'
    ;  No surprises here. I can take this example a bit further and try to format valid addresses to a uniform representation, as shown in the phone number example. My goal is to display every ip address in the "xxx.xxx.xxx.xxx" format, using leading zeros for 2 and 1 digit values.
    Regular expressions don't have any format models like for example the TO_CHAR function, so how could this be achieved? Thinking in regular expressions, I first have to find a way to make sure, that each single number is at least three digits wide. Using my example, this could look like this:
    WITH t AS (SELECT '127.0.0.1' ip
                 FROM dual
    SELECT t.ip, REGEXP_REPLACE(t.ip, '([0-9]+)(\.?)', '00\1\2')
      FROM t
    ;  Look at this: leading zeros. However, that first value "00127" doesn't look to good, does it? If you thought about using a second regular expression function to remove any excess zeros, you're absolutely right. Just take the past examples and think in regular expressions. Did you come up with something like this?
    WITH t AS (SELECT '127.0.0.1' ip
                 FROM dual
    SELECT t.ip, REGEXP_REPLACE(REGEXP_REPLACE(t.ip, '([0-9]+)(\.?)', '00\1\2'),
                                '[0-9]*([0-9]{3})(\.?)', '\1\2'
      FROM t
    ;  Think about the possibilities: Now you can sort a table with unformatted IP addresses, if that is a requirement in your application or you find other values where you can use that "trick".
    Since I'm on checking INET (internet) type of values, let's do some more, for example an e-mail address. I'll keep it simple and will only check on the
    "[email protected]", "[email protected]" and "[email protected]" format, where x represents an alphanumeric character. If you want, you can look up the corresponding RFC definition and try to build your own regular expression for that one.
    Now back to this one: At least one alphanumeric character followed by an "@" at sign which is followed by at least one alphanumeric character followed by a "." dot and exactly 3 more alphanumeric characters or 2 more characters followed by a "." dot and another 2 characters. This should be an easy one, right? Use some sample e-mail addresses and my brute force generator, you should be able to verify your solution.
    Here's mine:
    SELECT data
      FROM TABLE(regex_utils.gen_data('a1@.', 9))
    WHERE REGEXP_LIKE(data, '^[[:alnum:]]+@[[:alnum:]]+(\.[[:alnum:]]{3,4}|(\.[[:alnum:]]{2}){2})$', 'i'); Checking on valid domains, in my opinion, should be done in a second function, to keep the checks by itself simple, but that's probably a discussion about readability and taste.
    How about checking a valid URL? I can reuse some parts of the e-mail example and only have to decide what type of URLs I want, for example "http://", "https://" and "ftp://", any subdomain and a "/" after the domain. Using the case insensitive match parameter, this shouldn't take too long, and I can use this thread's URL as a test value. But take a minute to figure that one out for yourself.
    Does it look like this?
    WITH t AS (SELECT 'Introduction to regular expressions ... last part. URL
                 FROM dual
                UNION
               SELECT 'http://x/'
                 FROM dual
    SELECT t.URL
      FROM t
    WHERE REGEXP_LIKE(t.URL, '^(https*|ftp)://(.+\.)*[[:alnum:]]+(\.[[:alnum:]]{3,4}|(\.[[:alnum:]]{2}){2})/', 'i')
    Update: Improvements in 10g2
    All of you, who are using 10g2 or XE (which includes some of 10g2 features) may want to take a look at several improvements in this version. First of all, there are new, perl influenced meta characters.
    Rewriting my example from the first lesson, the WHERE clause would look like this:
    WHERE NOT REGEXP_LIKE(t.col1, '^\d+$')Or my example with searching decimal numbers:
    '^(\.\d+|\d+(\.\d*)?)$'Saves some space, doesn't it? However, this will only work in 10g2 and future releases.
    Some of those meta characters even include non matching lists, for example "\S" is equivalent to "[^ ]", so my example in the second part could be changed to:
    SELECT NVL(LENGTH(REGEXP_REPLACE('Having fun with regular expressions', '\S')), 0)
      FROM dual
      ;Other meta characters support search patterns in strings with newline characters. Just take a look at the link I've included.
    Another interesting meta character is "?" non-greedy. In 10g2, "?" not only means 0 or 1 occurrence, it means also the first occurrence. Let me illustrate with a simple example:
    SELECT REGEXP_SUBSTR('Having fun with regular expressions', '^.* +')
      FROM dual
      ;This is old style, "greedy" search pattern, returning everything until the last space.
    SELECT REGEXP_SUBSTR('Having fun with regular expressions', '^.* +?')
      FROM dual
      ;In 10g2, you'd get only "Having " because of the non-greedy search operation. Simulating that behavior in 10g1, I'd have to change the pattern to this:
    SELECT REGEXP_SUBSTR('Having fun with regular expressions', '^[^ ]+ +')
      FROM dual
      ;Another new option is the "x" match parameter. It's purpose is to ignore whitespaces in the searched string. This would prove useful in ignoring trailing/leading spaces for example. Checking on unsigned integers with leading/trailing spaces would look like this:
    SELECT REGEXP_SUBSTR(' 123 ', '^[0-9]+$', 1, 1, 'x')
      FROM dual
      ;However, I've to be careful. "x" would also allow " 1 2 3 " to qualify as valid string.
    I hope you enjoyed reading this introduction and hope you'll have some fun with using regular expressions.
    C.
    Fixed some typos ...
    Message was edited by:
    cd
    Included 10g2 features
    Message was edited by:
    cd

    Can I write this condition with only one reg expr in Oracle (regexp_substr in my example)?I meant to use only regexp_substr in select clause and without regexp_like in where clause.
    but for better understanding what I'd like to get
    next example:
    a have strings of two blocks separated by space.
    in the first block 5 symbols of [01] in the second block 3 symbols of [01].
    In the first block it is optional to meet one (!), in the second block it is optional to meet one (>).
    The idea is to find such strings with only one reg expr using regexp_substr in the select clause, so if the string does not satisfy requirments should be passed out null in the result set.
    with t as (select '10(!)010 10(>)1' num from dual union all
    select '1112(!)0 111' from dual union all --incorrect because of '2'
    select '(!)10010 011' from dual union all
    select '10010(!) 101' from dual union all
    select '10010 100(>)' from dual union all
    select '13001 110' from dual union all -- incorrect because of '3'
    select '100!01 100' from dual union all --incorrect because of ! without (!)
    select '100(!)1(!)1 101' from dual union all -- incorrect because of two occurencies of (!)
    select '1001(!)10 101' from dual union all --incorrect because of length of block1=6
    select '1001(!)10 1011' from dual union all) --incorrect because of length of block2=4
    select '10110 1(>)11(>)0' from dual union all)--incorrect because of two occurencies of (>)
    select '1001(>)1 11(!)0' from dual)--incorrect because (!) and (>) are met not in their blocks
    --end of test data

  • Regular expression in java -- specifically email

    Does anyone know how I can do a regular expression with java that is going to retrieve an email address pattern.
    For example, let's say i have a huge string
    this is a sample test. perhaps someoen can tell me how to retrieve my [email protected] from this string. sincerely yours [email protected]
    could someone explain to me how to retrieve these emai addresses most efficiently using java's regular expressions
    thanks
    stev

    A citing (http://jregex.sourceforge.net/examples-email.html):
    String someValidChars="[\\w.\\-]+";
    String someAlphaNums="\\w+";
    String dot="\\.";
    Pattern email=new Pattern(someValidChars + "@" + someValidChars + dot + someAlphaNums);

  • Regular Expressions + using them in Vector analysis

    Hello,
    I would be very glad for any hint concerning this problem:
    Consider this ilustrational code sample
    import java.util.regex.*;
    Vector sequence = new Vector();
            sequence.add("-");
            sequence.add("-");
            sequence.add("A");
            sequence.add("-");
            sequence.add("B");I want to find the first occurence of any alphabetical character ...I thought I can do it like this:
    int index = sequence.indexOf("\\w");or from the other point of view like this:
    int index = sequence.indexOf("[^-]");Unfortunately none of these are working. Do you know why and how to fix this? There are supposed to be only alphabetical characters and "-" character...
    thanks a lot
    adam

    mAdam wrote:
    well, the code I posted above should suit only as an illustration of my problem.
    ActualIy I have a bunch of those sequences in an Arraylist...it can be from 5 - 100 sequences(vectors) and I need to use some methods which are available only for Collections (frequency(), insertElementAt()...etc.). I am not a proffesional programmer so I do hope that I am using it correctly instead of "simple" String[][] BunchOfSequences = {seq1,seq2,...}I am not aware of any frequency() or insertElementAt() methods in one of Java's collection classes.
    Is it possible to use regular expressions to find a first occurence of a "a-z"(or "A-Z"..it doesnt matter) in a vector then? Or I just need to find it in a "for loop"?
    thx
    adamRegexes only work on Strings, not on collections holding Strings. So yes, you will need to use a for statement (or similar).
    List<String> list = ...
    for(String s : list) {
      if(s.matches("\\w")) {
    }

  • Regular expression checker

    hi,
    i am new to regular expression. i would like to know if there is a tool to check regular expressions? the tool should based on the entered regular expression display the result.
    thanks

    import java.util.regex.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class JavaRegxTest extends JFrame implements ActionListener{
      JTextField regxInput, textInput;
      JButton doMatchButton, resetButton, exitButton;
      JTextArea resultsArea;
      public JavaRegxTest(){
        super("JavaRegxTest");
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        Container cp = getContentPane();
        cp.setLayout(new GridLayout(2, 1));
        JPanel upPanel = new JPanel(new GridLayout(5, 1));
        upPanel.add(new JLabel("regular expression:   "));
        upPanel.add(regxInput = new JTextField(50));
        upPanel.add(new JLabel("sample text:          "));
        upPanel.add(textInput = new JTextField(50));
        JPanel buttonPanel = new JPanel(new GridLayout(1, 3));
        buttonPanel.add(resetButton = new JButton("RESET"));
        buttonPanel.add(doMatchButton = new JButton("MATCH"));
        buttonPanel.add(exitButton = new JButton("EXIT"));
        upPanel.add(buttonPanel);
        resetButton.addActionListener(this);
        doMatchButton.addActionListener(this);
        exitButton.addActionListener(this);
        resultsArea = new JTextArea(20, 60);
        resultsArea.setEditable(false);
        JScrollPane jsp = new JScrollPane(resultsArea);
        cp.add(upPanel);
        cp.add(jsp);
        setSize(550, 700);
        setVisible(true);
      public void actionPerformed(ActionEvent e){
        JButton btn = (JButton)(e.getSource());
        if (btn == exitButton){
          System.exit(0);
        else if (btn == resetButton){
          reset();
        else if (btn == doMatchButton){
          doMatch();
      /* clear text */
      void reset(){
        regxInput.setText("");
        textInput.setText("");
        resultsArea.setText("");
      /* display match results */
      void doMatch(){
        resultsArea.setText(resultsArea.getText() + "REGX=" + regxInput.getText()
         + "\n" + "TEXT=" + textInput.getText() + "\n");
        try{
          Pattern pat = Pattern.compile(regxInput.getText());
          String sampleText = textInput.getText();
          Matcher mat = pat.matcher(sampleText);
          int gc = mat.groupCount();
          for (int i = 0; i <= gc; ++i){ //for each capture group
            resultsArea.setText(resultsArea.getText()
             + "GROUP" + i + " : \n"); //GROUP0 == whole match
            while (mat.find()){ //display every matched parts
              resultsArea.setText(resultsArea.getText()
               + " " + mat.group(i) + "\n");
            mat.reset(sampleText); //go to next group
        catch(Exception e){
          resultsArea.setText(e.toString());
      public static void main(String[] args){
        JavaRegxTest jrt = new JavaRegxTest();
    }

Maybe you are looking for

  • Connected ipod to tv, picture but no sound

    i have a 30GB and i'm connecting to my tv witha 3rd party set of RCA cables i can see picture but no sound. don't know how to fix, did i do something wrong when i converted files or what? help, please

  • My brandnew earpod's controller doesn't work on my ipod touch.

    So 3 days ago I bought earpods, when i got home and tried them on the controller didn't work so today I went to exchange them but the controller still doesn't work. I tried them on my ipad 2 and the controller works fine. Is there a way to install th

  • OBIEE  Detail record with all the columns not showing up in drill down

    Hi When i drill down in the hierarchy it only shows me the key rather than the full detail record M heirarchy is Dim total reckey detail detailkey name type When i drill down on reckey, it shows only the detailkey and not oher columns. Is there somet

  • Oracle UCM Production instance

    we are proposing the oracle UCM 11g Solution to one of my client, here i have doubt about the list of products, please correct us? 1) Oracle Database 2) Oracle Weblogic Server 3) Oracle UCM 4) Oracle HTTP Server???????????? is this required? and we a

  • What is the best way to Sync Digital Output(TTL) with Analog Output?

    I am trying to generate Analog waveform that synchronize the rising edge of a digital signal(TTL). The ttl will be used as trigger for camera. The board I have is USB-6343X. In my draft,  I used a clock as ttl so I can tune frequency easily. Could an