Validate with a regular Expression

Hi Experts,


I want some regular expressions to format number as: nn/nn/nnnn

Expressions: total 10 digits only, and / after 4 digits, as / after 7 digits.


Test data:

SELECT ' 1111/18/01 ' AS NUM FROM DUAL

UNION

SELECT ' 01 / 01/2522 ' AS NUM FROM DUAL

UNION

SELECT ' 222/01/01 ' AS NUM FROM DUAL

UNION

SELECT ' 2222/01/1 ' AS NUM FROM DUAL

UNION

SELECT ' 2222/0/01 ' AS NUM FROM DUAL

UNION

SELECT ' 2522/01 ' AS NUM FROM DUAL

UNION

SELECT ' 01 / / 01' AS NUM FROM DUAL.


Desired output

REGEXP

-------------

1111/18/01

2522/01/01

Thanks in advance

BANNER

----------------------------------------------------------------

Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - production

I hope... This does not validate a date.

WITH the data AS

(SELECT "1111/18/01 ' AS NUM FROM DUAL

UNION

SELECT ' 01 / 01/2522 ' AS NUM FROM DUAL

UNION

SELECT ' 222/01/01 ' AS NUM FROM DUAL

UNION

SELECT ' 2222/01/1 ' AS NUM FROM DUAL

UNION

SELECT ' 2222/0/01 ' AS NUM FROM DUAL

UNION

SELECT ' 2522/01 ' AS NUM FROM DUAL

UNION

SELECT ' 01 / / 01' AS NUM FROM DUAL.

)

Select num

FROM THE DATA

where regexp_like(num,'^\d{4}/\d{2}/\d{2}$')

/

HTH

Tags: Database

Similar Questions

  • Analyze the Mac address with the regular expression matching

    Hello world

    I have a problem with the function of regular expression matching,

    I try to analyse the response both a query arp - a 192.168.0.15 to retrieve the MAC address of the remote IP address, I used the following regular expression: ^ ([0-9a-fA-F]{2}[:-]){5}([0-9a-fA-F]{2})$

    I wonder why should I do a subset of the first string to extract only the part of the MAC address. The regular Expression function is not able to recognize the regular expression directly in the middle of a string?

    I only works when I extracted the subset of tring right as in the picture below.

    Thanks for your replies.

    Get rid of the "^" at the beginning of your regular expression. You are ordering him to find the model at the beginning of the string.

  • Divide a CSV with a regular Expression

    I'm working on a script that will read the CMYK values from a CSV file and add the nuances of the Swatches palette. I can easily split the CSV entering a comma (.split(",");), but I can't seem to get a regular expression to separate by commas and new lines.

    Here is the code snippet I have right now is not working:

    var fileIn = new File("/Users/brianp/Desktop/AVL-PMS-TEMP.csv");
    fileIn.open();
    var csvIn = fileIn.read();
    fileIn.close();
    
    var regEx = "/,|\\n/";
    csvRecords = csvIn.split(regEx);  
    

    I am barking the wrong tree here?

    I could change the CSV advance to find all line breaks and replace them with commas, but it looks more elegant to adapt my code for the CSV file is delivered.

    Thanks in advance!

    csvRecords = csvIn.split(/[,\n\r]/);

    This is the shortcut. To preset the regex, to leave out the quotation marks:

    var regEx = / | \n/ ;

    Better to add the CR (\r) as well.

    Use the classes of characters [...] If you can instead of alternatives (... |...), they are more effective (allegedly).

    Peter

  • Help with the Regular Expressions and regexp_replace

    Oh great guru Oracle can I can receive assistance

    I need to clean the phone numbers that have been entered in the table per_phones of Oracle e-Business. Some of the phone numbers have hyphens, some have spaces and some have tank. I just want to get out all the figures and then re - format the number.

    E.g.
    914-123-1234... out (914) 123-1234
    9141231234... new (914) 123-1234
    914 123 1234... (914) 123-1234
    MyPhone... just null
    (914)-123-1234... (914) 123-1234

    I really tried to understand the instructions of regular expressions, but for some reason, I can't understand it.

    For example:

    SQL> with sample_data as (
      2   select '914-123-1234' phone_number from dual union all
      3   select '9141231234'                from dual union all
      4   select '914 123 1234'              from dual union all
      5   select '(914)-123-1234'            from dual
      6  )
      7  select regexp_replace(
      8           regexp_replace(phone_number, '\D')
      9         , '(...)(...)(....)'
     10         , '(\1) \2-\3'
     11         ) as formatted_num
     12  from sample_data
     13  ;
    
    FORMATTED_NUM
    --------------------------------------------------------------------------------
    (914) 123-1234
    (914) 123-1234
    (914) 123-1234
    (914) 123-1234
     
    
  • Number of shaped with preg_replace Regular Expression and PHP

    Hello

    I would like to add a 'dash' after every 3 digits in a given number (10 digits). For example, 9785678941 became 978-567-894-1. How could I achieve this with regular expression using PHP preg_replace?

    Thank you.

    The next solution is based on the example of "The use of backreferences followed literals digital" published on the php.net site.

    In accordance with the $string, $pattern, $replacement nomenclature which is the php.net example use, here´s my modification:

    <>

    $string = '9785678941';

    $pattern = ' / (\\d{3})(\\d{3})(\\d{3})(\\d{1)} /';

    $replacement = ' ${1}-{2}-${3}-${4}';

    echo preg_replace ($pattern, $replacement, $string);

    ?>

  • validate cfinput using regular expressions

    Hello

    can someone help me valditing a field of cfinput using regular expressions?

    First digit must be a number or a 'R '.

    Figure 2-15 can be anything without special characters. Figure 2-15 can also be empty.

    I try this, but it does not work (sorry I'm a beginner using regex).

    < cfinput type = "text" name = "field1" required = "yes" validate = 'regular_expression' pattern = "[0 - 9Rr] [0 - 9a - zA - Z]" * "maxlength ="15">"

    Thank you for advice!

    Claudia

    ^ [0 - 9Rr]([0-9a-zA-Z]{1,14})? $

  • Form validation helps with the regular Expression [a-zA-Z]

    I'm trying to use the regular expression [a-zA-Z] to allow only upper or lowercase WITHOUT SPACES. With the help of [a-zA-Z] allows space and numbers.

    Could someone give me a point in the right direction?

    Thank you!

    RGNelson wrote:

    I'm trying to use the regular expression [a-zA-Z] to allow only upper or lowercase WITHOUT SPACES. With the help of [a-zA-Z] allows space and numbers.

    Could someone give me a point in the right direction?

    Please try with the following regular expression, which should work for text entry fields 'a line' well standard.

    ^ [A-Za-z] + $

    See you soon,.

    Günter

  • Need help with a regular expression

    I have a Zebra printer string that I want to analyze some information, but I can't get a single regex to do.

    The string is like the following:

    ↑ FT342, 695 ^ A0N, 83, 81 ^ FH\ ^ FDS/N: [[WIDGET]] ^ FS

    ^ FT793, 1170 ^ A0N, 67, 67 ^ FH\ ^ ea FD1. Widget #00123 ^ FS

    ^ FT793, 1170 ^ A0N, 67, 80 ^ FH\ ^ ea FD2. #00456 Widget Deluxe ^ FS

    ^ FT793, 1170 ^ A0N, 67, 90 ^ FH\ ^ FD #0789 ^ FS

    I want what is in red. It will vary from one label to the label. I will use the results to show to the user what label it is printing. Who is blue only varies, if that helps anything.

    Thanks for any help!

    Here would be a way using regular expressions. Again, you have to ignore the first entry and this version will add a blank entry in the last position of the table. Wil you have more entries if your label contains more than what you have posted...

  • Tips SQL - replace one OR perhaps with a regular expression?

    Hi all

    I have a small question. This bothers me for weeks, and I was wondering if anyone of you has another idea for this.

    Imagine the following table. This is a very stupid table. But look at the sample data. I have reproduced the issue I have with the 3 files.
    CREATE TABLE departments
    (
      dpt_id NUMBER(10), 
      dpt_name VARCHAR2(100)
    );
    
    INSERT INTO departments(dpt_id, dpt_name) VALUES(1, 'NIGER');
    INSERT INTO departments(dpt_id, dpt_name) VALUES(1, 'NIGERIA');
    INSERT INTO departments(dpt_id, dpt_name) VALUES(1, 'NIGER.0001');
    
    SELECT * 
      FROM departments 
     WHERE (dpt_name = 'NIGER' OR dpt_name LIKE 'NIGER.%');
    If I use one AS % of NIGER, I recover as NIGERIA (which I don't want). So, instead, I use this GOLD combination and it works well. But I was wondering if it can be done without the GOLD.

    Thank you

    Hello

    This example gets the results you requested:

    SELECT    *
    FROM        departments
    WHERE       REGEXP_LIKE ( dpt_name
                      , '^NIGER([^[:alpha:]].*)?$'
                    )
    ;
    

    Describe the desired results. With only 3 or 4 lines of sample data, it is very easy to get good results for the wrong reasons.

  • stuck with a regular Expression

    Clear the javascript by RegExp train file comments: [/] [*]. + [*] [/]
    It s nice work with comments like this:
    / * blah-blah-blah * /.
    But what about like this:
    /*
    bla
    bla
    bla
    */
    How can I 'say' - ANYTHING?

    Fuffel wrote:
    > Tent clear the javascript by RegExp file comments: [/] [*]. + [*] [/]
    > It s nice work with comments like this:
    > / * blah-blah-blah * /.
    > But what about like this:
    > /*
    > blah
    > blah
    > blah
    > */
    > How I can 'say' - ANYTHING?
    >
    In find/replace in DW, it seems to work, but test it:

    \/\*[\w\W]*?\*\/

    --

    E. Michael Brandt

    www.divaHTML.com
    www.divahtml.com/Products/scripts_dreamweaver_extensions.php
    According to the standard scripts and the Dreamweaver Extensions

    www.valleywebdesigns.com/vwd_Vdw.asp
    JustSo PictureWindow
    JustSo PhotoAlbum, and alia

    --

  • Problem with regular Expression

    Hello!!
    I have a problem with the regular expression. I want to validate only one word, and second are the same. To do this, I wrote a regex

    Model p=Pattern.compile("([a-z][a-zA-Z]*)\\s\1");
    Matcher m = p.matcher ("nikhil nikhil");
    Boolean t = m.matches ();
    If (t)
    System.out.println ("it's a game");
    on the other
    System.out.println ("is no match);

    The result I get is always 'there no match. "

    Your timely help will be very appreciated.

    Concerning

    Hello.

    You are missing a slash in the regex

    Pattern p = Pattern.compile("([a-z][a-zA-Z]*)\\s\\1");
    Matcher m = p.matcher("nikhil nikhil");
    boolean t = m.matches();
    if (t) {
        System.out.println("There is a match");
    } else {
        System.out.println("There is no match");
    }
    
  • regular expression for something that does not have a fixed sequence

    Hello

    Just having a little trouble with a regular expression. I have an input string and I want to find something that is not this string, so

    Input = Hello

    Match = Hello

    Football game? = False

    Entry = Hello1

    Match = Hello

    Football game? = False

    Input = Hello

    Match = goodbye

    Football game? = True

    As I thought that I understood it, to enter as a regular expression in the regular Expression.vi of Match would be ~ (Hello).

    If I understand as well, I can't do this by using the match pattern.

    Maybe you good people can correct me. Thank you!


  • regular expression for alarm url

    Hello

    I have a problem with the regular expression. I want to filter only the name of a dsc alarm url: \\EW-MONITOR\monitor\000_t-ist_STB-M1-AS. Alarms.HI must be 000_t-ist_STB-M1-AS. Someone has a tip for me?

    Best regards

    --
    Joachim

    If as jcarmody asked, the name will always be between 'monitor\' and '. '. Alarms"use the output matching sub regular expression corresponds to

     

    It takes the name from alam of the entire game.

  • regular expression to exclude spaces in the string

    Now that I'm that sleazy, I need help with a regular expression.

    They must pass (or permutations it):

    [00123]

    [R012]

    [r083]

    These should fail (or permutations it):

    [test]

    [I was here]

    [098 876]

    Ooh [29873 eifvuh]]

    I have most of it (the ' [' must be first; the '] "must be the last;) There must be some middle numbers, but I can't write an expression that will fail if there are 1 or more spaces in the string.

    Thank you!

    Tay

    Several possibilities: try this regular expression.

    ^\[[a-za-Z]*[0-9]+[a-zA-Z0-9]*\]$

  • regular expression to remove the zeros on the right

    I need a regular expression to remove the zeros after the decimal point. I tried (?.)<=\.\d+?)0+(?=\D|$) but="" i="" get="" a="" error="" about="" look="" behind="" not="" a="" fixed="" length="" or="" something="" like="" that.="" i="" am="" not="" a="" regex="" expert="" and="" i="" was="" wondering="" just="" how="" to="" do="" this="" with="" regular="" expression="" or="" some="" other="">

    Z.K. wrote:

    [...] or some other way.

    I tried and I tried but I couldn't crack with a regular expression, so I took the easy way.  The first match found pattern the comma and the other removes the zeros to the right of the rest.  It is not discriminate between numbers and all the rest, though.

Maybe you are looking for

  • Whence required % 22 get set % 3F % 22Override

    I am a student of the code examples for expressing a material Abstraction using LabVIEW OOP layer.  To the upper class of the Instrument, the two public methods, initialize Instrument and Instrument, are reported and are supposed to be overridden by

  • How to make Beep.VI run simultaneously?

    Hello I'm doing a basic data acquisition program, but I am running into a problem of synchronization. I have 4 microphones and speaker. The idea is to create a tone using Beep.vi, and then collect the 4 signals out of the pickups (which are spaced).

  • Need help to remove laptop computer MAGNIFER every time that startup is enabled

    I have a dell inspiron 1525 Vista OS.  Somehow a framework was haphazard and now MAGNIFYING GLASS appears opens each laptop time is started or restarted.  I went thru remove startup programs and disable Windows features.  But have had no success. Ple

  • My Documents disappeared from the library, although I can see them in the C drive

    The other day I copied all 'my documents' to another drive (for backup).   Now, when I try to use my library, he thinks that I have MOVED my documents on the backup drive. When I open the library in my C drive, it only shows public documents (for my

  • LR CC disappeared

    iMac with V10.11.5. The CC application displays that LR is "up-to-date."Wanted to export a collection and got no reply button export. Went to quit smoking with backup. Progress button was complete from the beginning and nothing happened; It seemed ju