Regular expression to check a value if it contains a specific word.

Hi All,
How can i check if a certain word exists in a value in regular expression ?
I have an attribute called Race. Race can contain the following:
White, Non-Hispanic
Black, Non-Hispanic
White, Non Hispanic
Black, Non Hispanic
White, NonHispanic
Non-Hispanic, white
Non Hispanic - black
What i want is to check if my value contains the word "NON" (NON can be at the beginning, middle or end), if it does, parse it and return it.
This is what I have, however I want to make sure it covers all cases and not missing anything else
select REGEXP_SUBSTR(UPPER(trim('Black, Non-Hispanic')), '[NON]+') from dual;Thanks in advance.

Rooney wrote:
Could you please explain what are the 2 ones's for ?The two 1 are not really needed for this. It is just taht the syntax requires those parameters when I add the fifth parameter.
http://docs.oracle.com/cd/E14072_01/server.112/e10592/functions148.htm
First 1 is where the search starts (same as in substr('Abc',1))
Second 1 is the number of occurences. Here meaning return the first occurence that was found. Replace it with 2 in my next example to see a (very slight) difference.
Also 'NON' alone will not cover all cases ?But you don't have non alone. You have regexp with non + upper. The 'i' replaces the upper. Also the output is slightly different. the 'i' version will return the same capitalization as it was found in the original. It depends a little what you want to achieve. And of cause INSTR will give the same info as your version. if the result is > 0 it means NON was found.
with testdata as (select 'White,Non-Hispanic' str from dual union all
                  select 'Non-White,nOn-Hispanic' str from dual union all
                  select 'White,Hispanic' str from dual
/* end of test data creation */
select str,
      REGEXP_SUBSTR(UPPER(TRIM(str)), 'NON') regexp1,
      REGEXP_SUBSTR(str, 'NON',1,1,'i') regexp2,
      instr(upper(str),'NON') instr
from testdata;
STR                    REGEXP1                REGEXP2                INSTR
White,Non-Hispanic     NON                    Non                        7
Non-White,Non-Hispanic NON                    Non                        1
White,Hispanic                                                           0

Similar Messages

  • Regular expression to check the sequence of strings

    HI,
    I am validating an EDI document like as follows
    ISA*XX*XXXXXXXXXXXXXXX*XX*XXXXXXXXXXXXXXX*030130*0912*~IEA*1*000005900~
    I need to create a regular expression which checks ISA should always occur before IEA.
    Please help me if you have any hints.
    Thanks.

    Thanks.I had taken that into consideration.
    But using regular expression I could say
    ISA* only once
    IEA* only once
    And
    ISA before IEA
    Any hints how to specify "before"/sequence using Regular expression ?
    I agree sometime using basic String operation we can do this.

  • Regular Expression to Check number with at least one decimal point

    Hi,
    I would like to use the REGEX_LIKE to check a number with up to two digits and at least one decimal point:
    Ex.
    10.1
    1.1
    1
    12
    This is what I have so far. Any help would be appreciated. Thanks.
    if regexp_like(v_expr, '^(\d{0,2})+(\.[0-9]{1})?$') t

    Hi,
    Whenever you have a question, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
    See the forum FAQ: https://forums.oracle.com/message/9362002
    SammyStyles wrote:
    Hi,
    I would like to use the REGEX_LIKE to check a number with up to two digits and at least one decimal point:
    Ex.
    10.1
    1.1
    1
    12
    This is what I have so far. Any help would be appreciated. Thanks.
    if regexp_like(v_expr, '^(\d{0,2})+(\.[0-9]{1})?$') t
    Do you really mean "up to two digits", that is, 3 or more digits is unacceptable?  What if there are 0 digits?  (0 is less than 2.)
    Do you really mean "at least one decimal point", that is, 2, 3, 4 or more decimal points are okay?  Include some examples when you post the sample data and results.
    It might be more efficient without regular expressions.  For example
    WHERE   TRANSLATE ( str              -- nothing except digits and dots
                      , 'A.0123456789'
                      , 'A'
                      )   IS NULL
    AND     str           LIKE '%.%'     -- at least 1 dot
    AND     LENGTH ( REPLACE ( str       -- up to 2 digits
                    )     <= 2

  • Unique regular expression to check if a string contains letters and numbers

    Hi all,
    How can I verify if a string contains numbers AND letters using a regular expression only?
    I can do that with using 3 different expressions ([0-9],[a-z],[A-Z]) but is there a unique regular expression to do that?
    Thanks all

    Darin.K wrote:
    Missed the requirements:
    single regex:
    ^([[:alpha:]]+[[:digit:]]+|[[:digit:]]+[[:alpha:]])[[:alnum:]]*$
    You either have 1 or more digits followed by 1 or more letters or 1 or more letters followed by 1 or more digits. Once that is out of the way, the rest of the string must be all alphanumerics.  The ^ and $ make sure the whole string is included in the match.
    (I have not tested this at all, just typed it up hopefully I got all the brackets in the right place).
    I think you just made my point.  TWICE.  While the lex class would be much more readable as a ring.... I know all my brackets are in the correct places and don't need to hope.
    Jeff

  • XPATH expression to check blank value

    Hi,
    I have xml File to IDocs scenario. Single xml file will contain the data related to Order Create and Order Change. I have implemented the same using Conditional Interface Determination. Depending upon following conditions the data needs to be sent to either ZORDERS.ORDER05 or ZORDCHG.ORDERS05 IDoc
    1. if servicetemplateid = 'SRNonStandard' and myerpordernumber = blank  then create order.
    2. if service templateid = 'SRForEvents' and myerpordernumber <> blank then change sales order.
    I tried all possible functions of xpath but couldnt determine the interface.
    The source file will look something like this. So the first record must be sent to ZORDCHG.ORDERS05 and second record to ZORDERS.ORDERS05
    <all>
         <table name="SvcMyServiceRequestNLExpView">
              <record id="1">
                   <datacol name="client">010</datacol>
                   <datacol name="salesorg">0702</datacol>
                   <datacol name="servicetemplateid">SRForEvents</datacol>
                   <datacol name="myerpordernumber">123</datacol>
              </record>
              <record id="2">
                   <datacol name="client">010</datacol>
                   <datacol name="salesorg">0702</datacol>
                   <datacol name="servicetemplateid">SRNonStandard</datacol>
                   <datacol name="myerpordernumber"></datacol>
              </record>
         </table>
    </all>
    I have given the following conditions in interface determination
    1. for ZORDERS.ORDERS05
    (/all/table/record[(datacol/@name = 'servicetemplateid') and (datacol = 'SRNonStandard' or datacol = 'SRForEvents')] EX  AND /all/table/record[(datacol/@name = 'myerpordernumber') and (datacol='')] EX )
    2. for ZORDCHG.ORDERS05
    (/all/table/record[(datacol/@name = 'servicetemplateid') and (datacol = 'SRNonStandard' or datacol = 'SRForEvents')] EX  AND /all/table/record[(datacol/@name = 'myerpordernumber') and (datacol!='')] EX )
    I have tried not(datacol = '') instead of !. I have also tried string-length function but it doesnt determine the interface correctly. i.e if the file contains only Order create Idocs, it will still call orders change interface mapping
    The problem is that XPath is not able to compare the blank properly.
    Please suggest.
    Thanks Nilesh.

    Hey Thanks Alex,
    Your solution helped me a lot to place the brackets and work with attributes. However, XPATH doesnt determine a blank. But I kept the blank condition in the operator itself(i.e outside xpath) and checked only the attribute in the XPATH and it works fine now. I used the following:
    In condition editor one condition to check servicetemplateid attribute using exists. And second condition to check myerpordernumber = blank using equals operator.
    For Orders Create
    (/all/table/record[(datacol/@name = 'servicetemplateid') and (datacol = 'SRNonStandard' or datacol = 'SRForEvents')] EX  AND /all/table/record/datacol[@name = 'myerpordernumber'] = )
    For Orders Change
    (/all/table/record[(datacol/@name = 'servicetemplateid') and (datacol = 'SRNonStandard' or datacol = 'SRForEvents')] EX  AND /all/table/record/datacol[@name = 'myerpordernumber'] u2260 )
    Thanks Nilesh

  • Regular Expression to check for some of the special characters

    Can someone please provide me a RegularExpression to check if a string contains any of the speical characters i.e. *!@#$%^&*()_+ []{}:;',./<>?~`*
    Thanks
    Edited by: whitesox12 on Apr 3, 2008 9:46 PM

    [*!@#$%\^&()_+\[\]{}:;',./?~`]In a Java string literal, a backslash should be written as two consecutive backslashes.

  • 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

  • Checking a number sequence with regular expressions

    Hello,
    Suppose I have a text in the pattern:
    A1=ha,A2=bla,A3=cha,...
    I don't know how many sections of "A#=$" (# denotes number, $ denotes text) will be in the text, but I want to verify that the numbers of the A's form the natural ascending number sequence (i.e 1,2,3,...). I prefer to use regular expressions to do this, but if there's another way, I will be glad to hear it too.
    Therefore my question is: How can I use regular expressions to check for a sequence of numbers? I know I can search for groups I've caught previously in the expression, but how can I compute the next number in the sequence from the group and search for the result?
    Thank you very much!

    What I'd do--and I'm not saying this is optimal, just what pops immediately to mind--is have a regex that matches "A(\\d+)=" (assuming the ha, bla, cha can never be "A1" etc.--if they can, you can still do it, but it's more complicated), then you iterate with the Matcher, and each time, you get the Integer.valueOf what you matched. You keep track of the last value, and compare the current to the last. If current is < last (or <= last, depending on your requirements), fail.
    Something like this. I don't recall Matcher's methods off the top of my head, so you'll have to fix the details.
    Matcher m = Pattern.matcher("A(\\d+)=");
    int maxSoFar = Integer.MIN_VALUE;
    while (m.matches(input)) {
        int current = Integer.parseInt(m.getMatchedField("$1"));
        if (current <= maxSoFar) {
            // fail
        else {
            maxSoFar = current;
    } maxSoFar =

  • Regular expression: check for the presence of special characters.

    I have the following requirement:
    I need to check for the presence of the following characters in a keyword: @, #, > if any of these characters are present, then they need to be stripped off, before going further. Please let me know the regular expression to check for these characters.

    I am trying to extend the same logic for the following characters:
    .,‘“?!@#%^&*()-~<>[]{}\+=`©® . here is the code fragment:
    Pattern kValidator = Pattern.compile("[\\.,\\‘\\“?!@#%^&*()-~<>[]{}\\+=\\`©®]");
    Matcher kMatcher = kValidator.matcher(keyWord);
    if (kMatcher.find(0)) {
    keyWord = keyWord.replaceAll("[.,\\‘\\“?!@#%^&*()-~<>[]{}\\+=\\`©®]", " ");
    }I get the following error. This error is from the weblogic command window. I dont understand these special characters.
    Error:
    28 Oct 2008 12:27:48 | INFO  | SearchController   | Exception while fetching search results in controller:Unclosed character class near index
    39
    [\.,\&#915;Çÿ\&#915;Ç£?!@#%^&*()-~<>[]{}\+=\`&#9516;&#8976;&#9516;«]
                                           ^
    java.util.regex.PatternSyntaxException: Unclosed character class near index 39
    [\.,\&#915;Çÿ\&#915;Ç£?!@#%^&*()-~<>[]{}\+=\`&#9516;&#8976;&#9516;«]
                                           ^
            at java.util.regex.Pattern.error(Pattern.java:1650)
            at java.util.regex.Pattern.clazz(Pattern.java:2199)
            at java.util.regex.Pattern.sequence(Pattern.java:1727)
            at java.util.regex.Pattern.expr(Pattern.java:1687)
            at java.util.regex.Pattern.compile(Pattern.java:1397)
            at java.util.regex.Pattern.<init>(Pattern.java:1124)
            at java.util.regex.Pattern.compile(Pattern.java:817)

  • How to get year value using regular expression

    Hi,
    I have a different format of date such as 2004-01-03, 2003/01, 05/06/2005, 06-05-2007
    How can I get only the year value using regular expression? The year value is always in 4 digits
    Thanks in advance

    sabre150 wrote:
    JosAH wrote:
    \d{4}Is this the Jos I knew who poured scorn on anything to do with regex? Is this the Jos I knew who said that the 'pimping lemon' stopped regex being of any real use?It wasn't me; honest, I'm innocent: one of my parrots walked over my keyboard; I wouldn't be able to type such nonsense; naughty parrot! No cookie!
    kind regards,
    Jos
    ps. regexes can only survive the baby-pumping-lemma; they all die a horrible death with the real-men-pumping lemma! So there.

  • CharAt in a keystroke event using regular expression

    I'm working on a canadian postal code field.  I'm using a regular expression to validate the value.
    //accepts "A9A 9A9", "A9A9A9" or "" as valid entries excluding letters D, F, I, O, Q, U and W as well as Z as the first digit.
    var re = /^[ABCEGHJKLMNPRSTVXY]\d[ABCEGHJKLMNPRSTVWXYZ]( )?\d[ABCEGHJKLMNPRSTVWXYZ]\d$|^$/i;
    if(re.test(event.value) == false){
    app.alert("Code postal invalide", 0, 0,"CODE POSTAL");
    event.value = "";
    I also added a keystroke event to prescan every digit and toUpperCase() them.
    //accepts letters, numbers, backspace or spaces
    var re = /[ABCEGHJKLMNPRSTVWXYZ]|\d|^$|\s/i;
    if (!event.willCommit){
    if(re.test(event.change) == false){
      event.rc = false;
    else{
      event.change = event.change.toUpperCase();
    I want to Replicate the behavior of an arbitrary mask where I can force a character to appear at a specific position.  In this example, instead of letting the user decide wether he adds a "space" or not between the two parts of the code, I want to:
    1-Remove "\s" in the keystroke regexp so the user cannot use "space";
    2-Replace "( )?" for "( )" in the validation regexp;
    3-Force a space at charAt(3).
    Is it possible to have it appear while the user is still typing or is my only option to change the value once committed or as a cutom format script?
    In the same manner, is it possible to specify a different regexp keystroke depending on the position of each character?
    charAt(0), charAt(2), charAt(5) would be letters
    charAt(1), charAt(6), charAt(7), would be numbers
    charAt(3), would automatically add a "space"
    in the end, I want the same behavior as an arbitrary mask without the annoying alert when entering a wrong digit.

    The entire string validation is different from the keystroke validation. The keystroke validation can check each keystroke as it is typed while the string validation can only process the entire string at one time.
    You need to break your RegExp to describe the requirement for each character. You can even specify the possible number of repetitions of the pattern.
    A discussion on to create keystroke validations would be far too long for a post in a forum.
    Acuumnen has an ebook about Acrobat forms and has a couple of chapters to some simple validation and formatting scripts.

  • 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.

  • Requirement to update a column by using Regular Expression

    Hi All,
        I have a requirement to update a column which is having values like below code.
    based on the conditinos I need to update from ‘E’ to ‘Z’.  Few positions I need to update and remaining positions I need leave as it is.
    How I can achive this requirement by using regular expression regexp_replace.
    Actual value --> 'AEAAAEAA    EE    AA    EE    AA    EE    EEEAA    AA    AA       '
    After update -->  'AZAAAZAA    EE    AA    EE    AA    EE    EEEAA    AA    AA       '

    below is my requirement. I am adding the conditions dynamically as per the conditions. I dont know the position of the E. If 'E' is in any position I need to update with 'Z' if that 'E' satisfy the condition.
    I dont want to update all the E's to Z's.
    I want to update specific E's which satisfy the condition.
        IF l_kwhhilow >= 1 THEN
            l_where := l_where||' SUBSTR(OVERRIDEFIELD,1,1) = ''E'' OR ';
            l_exp := l_exp||'Z';
        ELSE
            l_exp := l_exp||'\1';
        END IF;
        IF l_kwhilow >= 1 THEN
            l_where := l_where||' SUBSTR(OVERRIDEFIELD,2,1) = ''E'' OR ';
             l_exp := l_exp||'Z';
        ELSE
            l_exp := l_exp||'\2';
        END IF;
        IF l_kvahilow >= 1 THEN
            l_where := l_where||' SUBSTR(OVERRIDEFIELD,3,1) = ''E'' OR ';
             l_exp := l_exp||'Z';
        ELSE
            l_exp := l_exp||'\3';
        END IF;
        IF l_kvarhilow >= 1 THEN
            l_where := l_where||' SUBSTR(OVERRIDEFIELD,4,1) = ''E'' OR ';
             l_exp := l_exp||'Z';
        ELSE
            l_exp := l_exp||'\4';
        END IF;
        IF l_todkwh1hilow >= 1 THEN
            l_where := l_where||' SUBSTR(OVERRIDEFIELD,5,1) = ''E'' OR ';
             l_exp := l_exp||'Z';
        ELSE
            l_exp := l_exp||'\5';
        END IF;
        IF l_todkwh2hilow >= 1 THEN
            l_where := l_where||' SUBSTR(OVERRIDEFIELD,6,1) = ''E'' OR ';
             l_exp := l_exp||'Z';
        ELSE
            l_exp := l_exp||'\6';
        END IF;
        l_exp := ''''||l_exp||'''';
        l_exp1 := '\1\2\3\4'||l_exp1;
        IF l_todkw1hilow >= 1 THEN
            l_where := l_where||' SUBSTR(OVERRIDEFIELD,11,1) = ''E'' OR ';
             l_exp1 := l_exp1||'Z';
        ELSE
            l_exp1 := l_exp1||'\5';
        END IF;
        IF l_todkw2hilow = 1 THEN
            l_where := l_where||' SUBSTR(OVERRIDEFIELD,12,1) = ''E'' OR ';
             l_exp1 := l_exp1||'Z';
        ELSE
            l_exp1 := l_exp1||'\6';
        END IF;
        l_exp1 := ''''||l_exp1||'''';
    IF i give 10 in the regexp_replace it is not working.
    SET OVERRIDEFIELD =     REGEXP_REPLACE(SUBSTR(overridefield,1,6), ''(.)(.)(.)(.)(.)(.)'','||l_exp||')'||
                                              ' ||REGEXP_REPLACE(SUBSTR(overridefield,7,6), ''(.)(.)(.)(.)(.)(.)'','||l_exp1||')'||
                                              ' ||SUBSTR(overridefield,13)'||

  • Regular Expression for Invalid Number

    Hi everyone,
    I am using oracle version as follows:
    SQL> select * from v$version;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Prod
    PL/SQL Release 10.2.0.4.0 - Production
    CORE    10.2.0.4.0      Production
    TNS for 32-bit Windows: Version 10.2.0.4.0 - Production
    NLSRTL Version 10.2.0.4.0 - Production
    I am using regular expression to replace invalid values from a table.
    I received oracle error stating "ORA-01722 invalid number"
    My query looks like this:
    SELECT DISTINCT
    MRC_KEY,
    PURPOSE_CD,
    RESIDENCE_DESC,
    to_number(regexp_replace(ICAP_GEN_MADAPTIVE,'[+. ]?0?0?(\d+)[-.]?','\1')) as ICAP_GEN_MADAPTIVE,
    From
    MRRC_INT
    I am not sure what are the invalid values in the table so I can write regexp accordingly.
    Any guidance is highly appreciated!
    Thanks in advance
    J

    Or use DML error logging:
    create table t1
      (col1 number);
    exec dbms_errlog.create_error_log ('t1','t1_errors')
    insert into t1
    with t as
      (select '1' col from dual union all
       select '1.1' col from dual union all
       select '.11' col from dual union all
       select '0.11' col from dual union all
       select '-1' col from dual union all
       select '1,1' col from dual union all
       select '11a' col from dual union all
       select '1d' col from dual union all
       select '1e6' col from dual union all
       select '1e6.1' col from dual union all
       select '1e' col from dual
    select col
    from t
    log errors into t1_errors
    reject limit 20
    col col1 for 999,999,999.99
    select * from t1;
               COL1
               1.00
               1.10
                .11
                .11
              -1.00
       1,000,000.00
    col col1 for a30
    select * from t1_errors;
    ORA_ERR_NUMBER$ ORA_ERR_MESG$                  ORA_ERR_ROWID$       OR ORA_ERR_TAG$         COL1
               1722 ORA-01722: invalid number                           I                       1,1
               1722 ORA-01722: invalid number                           I                       11a
               1722 ORA-01722: invalid number                           I                       1d
               1722 ORA-01722: invalid number                           I                       1e6.1
               1722 ORA-01722: invalid number                           I                       1e

  • Carriage Return - Regular Expression

    Hi guys,
    I'm looking for an effective method to speed up the extreme optimization process in my work (finally to not do it manually).
    The particulary issue is to find a good regular expression to replace the carriage returns in the source code with nothing.
    I searched on the net, and many sources converge on the RegExr tool: http://gskinner.com/RegExr/
    I tried to set up an expression to solve my problem but it doesn't work. The expression that was generated by the tool is:
    Find: /\r/g Replace: (none) 
    When i enter the expression in Dreamweaver Find & Replace panel (with regular expression option checked and match case, etc. unchecked), it seems to not produce any valid change on the code.
    I'm sure that i'm wrong something.
    Anyone have suggestion?
    Thanks all for help.

    I don't understand the point of this.  There's very little to be gained from removing white space from code. And if you do this to JavaScript, you'll very likely break the code.
    Safer method, go to Edit > Preferences > Code Format > click on Tag Libraries and define how you want your code formatted.  Then  apply with Command > Apply Source Formatting.
    Nancy O.

Maybe you are looking for