Need PL/SQL - Oracle Regular Expressions help

Hi all,
I have to create script some schema in oracle database to update our SVN. And after create DDL scrip need to do some modification (Ex: add columns). Example as follows,
After create table DDL original scripts as follows,
--table format 1
CREATE TABLE "USER"."TABLE1"
        "COLUMN1"   NUMBER,
        "COLUMN2"   NUMBER,
        "COLUMN3"   NUMBER,
        "COLUMN4"   VARCHAR2(20 BYTE),
        PRIMARY KEY ("COLUMN1") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "T1" ENABLE
    PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING STORAGE
        INITIAL 35651584 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT
    TABLESPACE "T1" ;
CREATE INDEX "USER"."TABLE1_COLUMN2" ON "USER"."TABLE1"
        "COLUMN2"
    PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE
        INITIAL 196608 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT
    TABLESPACE "T1" ;
CREATE INDEX "USER"."TABLE1_COLUMN3" ON "SPIDERP4"."TABLE1"
        "COLUMN3"
    PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE
        INITIAL 458752 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT
    TABLESPACE "T1" ;
--table format 2
CREATE TABLE "USER"."TABLE2"
        "COLUMN1"  NUMBER,
        "COLUMN2"  NUMBER,
        "COLUMN3"  NUMBER,
        "COLUMN4"  VARCHAR2(20 BYTE)
    PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING STORAGE
        INITIAL 35651584 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT
    TABLESPACE "T1" ;
CREATE INDEX "USER"."TABLE2_COLUMN1" ON "USER"."TABLE2"
        "COLUMN1"
    PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE
        INITIAL 196608 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT
    TABLESPACE "T1" ;
CREATE INDEX "USER"."TABLE2_COLUMN2" ON "SPIDERP4"."TABLE2"
        "COLUMN2"
    PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE
        INITIAL 458752 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT
    TABLESPACE "T1" ;
I need to include following amendment to above table scripts (expecting results),
--1
CREATE TABLE "USER"."TABLE1"
        "COLUMN1"   NUMBER,
        "COLUMN2"   NUMBER,
        "COLUMN3"   NUMBER,
        "COLUMN4"   VARCHAR2(20 BYTE),
        _*"COLUMN5"   NUMBER(3,0) DEFAULT 0,*_
        PRIMARY KEY ("COLUMN1") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "T1" ENABLE
    PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING STORAGE
        INITIAL 35651584 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT
    TABLESPACE "T1" ;
CREATE INDEX "USER"."TABLE1_COLUMN2" ON "USER"."TABLE1"
        "COLUMN2"
    PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE
        INITIAL 196608 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT
    TABLESPACE "T1" ;
CREATE INDEX "USER"."TABLE1_COLUMN3" ON "SPIDERP4"."TABLE1"
        "COLUMN3"
    PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE
        INITIAL 458752 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT
    TABLESPACE "T1" ;
--2
CREATE TABLE "USER"."TABLE2"
        "COLUMN1"  NUMBER,
        "COLUMN2"  NUMBER,
        "COLUMN3"  NUMBER,
        "COLUMN4"  VARCHAR2(20 BYTE),
        _*"COLUMN5"  NUMBER(3,0) DEFAULT 0*_
    PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING STORAGE
        INITIAL 35651584 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT
    TABLESPACE "T1" ;
CREATE INDEX "USER"."TABLE2_COLUMN1" ON "USER"."TABLE2"
        "COLUMN1"
    PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE
        INITIAL 196608 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT
    TABLESPACE "T1" ;
CREATE INDEX "USER"."TABLE2_COLUMN2" ON "SPIDERP4"."TABLE2"
        "COLUMN2"
    PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE
        INITIAL 458752 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT
    TABLESPACE "T1" ;
/Note:
I need solution apart from these conditions,
1)Table cannot be modify before create DDL (DDL creating using this method “dbms_metadata.get_ddl” ).
2)This is automated processes manual modification cannot be allow.
3)We cannot hard-coded any Dynamic Values because above create DDL table just for explain my question.(**note : “PCTFREE” ,” PRIMARY KEY”, “),”.... above values can be hard-coded**)
Thanks
Tharindu Dhaneenja
Edited by: Dhaneenja on Mar 14, 2011 11:16 PM
Edited by: Dhaneenja on Mar 14, 2011 11:17 PM
Edited by: BluShadow on 15-Mar-2011 09:08
Added {noformat}{noformat} tags                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

not very safe code to do what you are looking for...
=================test data========================
SET ECHO ON FEED OFF LIN 2000 PAGES 9999  LONG 1000000 LONGC 1000 TRIMS ON;
EXEC DBMS_METADATA.SET_TRANSFORM_PARAM( DBMS_METADATA.SESSION_TRANSFORM,'SQLTERMINATOR',TRUE);
DROP USER u CASCADE;
GRANT DBA TO u IDENTIFIED BY u;
CREATE TABLE u.t1
   c1   NUMBER,
   c2   NUMBER,
   c3   NUMBER,
   c4   NUMBER,
   PRIMARY KEY (c1)
CREATE TABLE u.t2
   c1   NUMBER,
   c2   NUMBER,
   c3   NUMBER,
   c4   NUMBER
CREATE TABLE u.t3
   c1   NUMBER NOT NULL,
   c2   NUMBER,
   c3   NUMBER
CREATE TABLE u.t4 (c1 NUMBER    REFERENCES u.t1);
CREATE TABLE u.t5 (c1 NUMBER UNIQUE);
CREATE TABLE u.t6 (c1 NUMBER CHECK (c1 > 0));
CREATE TABLE u.t7 (c1 NUMBER NOT NULL);=================query========================
SELECT CASE
          WHEN (SELECT COUNT (*)
                  FROM dba_tab_columns tc
                 WHERE tc.owner = o.owner AND tc.table_name = o.object_name) >
                  0
          THEN
             SUBSTR (
                DBMS_METADATA.get_ddl (object_type, object_name, owner),
                1,
                INSTR (
                   DBMS_METADATA.get_ddl (object_type, object_name, owner),
                   CHR (10),
                   1,
                   2
                   + (SELECT COUNT (*)
                        FROM dba_tab_columns tc
                       WHERE tc.owner = o.owner
                             AND tc.table_name = o.object_name)))
             || CASE
                   WHEN (SELECT COUNT (*)
                           FROM sys.obj$ so,
                                sys.cdef$ scd,
                                sys.con$ sc,
                                sys.user$ su
                          WHERE     su.user# = so.owner#
                                AND so.obj# = scd.obj#
                                AND scd.con# = sc.con#
                                AND so.obj# = scd.obj#
                                AND scd.type# != 7
                                AND so.name = o.object_name
                                AND su.name = o.owner) = 0
                   THEN
                      ',column5 number(3,0) default 0'
                   ELSE
                      'column5 number(3,0) default 0,'
                END
             || SUBSTR (
                   DBMS_METADATA.get_ddl (object_type, object_name, owner),
                   INSTR (
                      DBMS_METADATA.get_ddl (object_type, object_name, owner),
                      CHR (10),
                      1,
                      2
                      + (SELECT COUNT (*)
                           FROM dba_tab_columns tc
                          WHERE tc.owner = o.owner
                                AND tc.table_name = o.object_name)))
          ELSE
             DBMS_METADATA.get_ddl (object_type, object_name, owner)
       END
          t
  FROM dba_objects o
WHERE owner = 'U';=================output========================
  CREATE TABLE "U"."T1"
   (    "C1" NUMBER,
        "C2" NUMBER,
        "C3" NUMBER,
        "C4" NUMBER,
column5 number(3,0) default 0,
         PRIMARY KEY ("C1")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255
  TABLESPACE "USERS"  ENABLE
   ) SEGMENT CREATION DEFERRED
  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
  TABLESPACE "USERS" ;
  CREATE UNIQUE INDEX "U"."SYS_C0025504" ON "U"."T1" ("C1")
  PCTFREE 10 INITRANS 2 MAXTRANS 255
  TABLESPACE "USERS" ;
  CREATE TABLE "U"."T3"
   (    "C1" NUMBER NOT NULL ENABLE,
        "C2" NUMBER,
        "C3" NUMBER
,column5 number(3,0) default 0
   ) SEGMENT CREATION DEFERRED
  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
  TABLESPACE "USERS" ;
  CREATE TABLE "U"."T4"
   (    "C1" NUMBER,
column5 number(3,0) default 0,
         FOREIGN KEY ("C1")
          REFERENCES "U"."T1" ("C1") ENABLE
   ) SEGMENT CREATION DEFERRED
  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
  TABLESPACE "USERS" ;
  CREATE TABLE "U"."T2"
   (    "C1" NUMBER,
        "C2" NUMBER,
        "C3" NUMBER,
        "C4" NUMBER
,column5 number(3,0) default 0
   ) SEGMENT CREATION DEFERRED
  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
  TABLESPACE "USERS" ;
  CREATE TABLE "U"."T5"
   (    "C1" NUMBER,
column5 number(3,0) default 0,
         UNIQUE ("C1")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255
  TABLESPACE "USERS"  ENABLE
   ) SEGMENT CREATION DEFERRED
  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
  TABLESPACE "USERS" ;
  CREATE UNIQUE INDEX "U"."SYS_C0025507" ON "U"."T5" ("C1")
  PCTFREE 10 INITRANS 2 MAXTRANS 255
  TABLESPACE "USERS" ;
  CREATE TABLE "U"."T6"
   (    "C1" NUMBER,
column5 number(3,0) default 0,
         CHECK (c1 > 0) ENABLE
   ) SEGMENT CREATION DEFERRED
  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
  TABLESPACE "USERS" ;
  CREATE TABLE "U"."T7"
   (    "C1" NUMBER NOT NULL ENABLE
,column5 number(3,0) default 0
   ) SEGMENT CREATION DEFERRED
  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
  TABLESPACE "USERS" ;

Similar Messages

  • Oracle regular expression help

    I have worked with regular expressions a little bit in unix scripting.
    I need to diff two schemas to look for missing objects.
    Problem: I changed the naming conventions.
    My objects used to end with '_T' and now end with '_MV'
    I cant use regular instr because I can have
    HELLO_TYPES_T or I could have HELLO_T
    I want to trim off the last T and MV and then do a minus to see if I am missing objects.
    I I think I need to use regexp_instr with an end of line regular expression, but I can't get the syntax correct. Can someone give me a hand?

    Well, how about this:
    SQL> with schema1
      2   as ( select  'HELLO_TYPES_T' obj from dual union all
      3        select  'HELLO_T' from dual union all
      4        select  'TYPES_T' obj from dual union all
      5        select  'HELLO_TYPES_MV' obj from dual union all
      6        select  'HELLO_MV' from dual union all
      7        select  'TYPES_MV' obj from dual union all    
      8        select  'OBJECTS_T' obj from dual )
      9  ,    schema2
    10   as ( select  'HELLO_TYPES_T' obj from dual union all
    11        select  'HELLO_T' from dual union all
    12        select  'TYPES_T' obj from dual union all
    13        select  'HELLO_TYPES_MV' obj from dual union all
    14        select  'HELLO_MV' from dual union all
    15        select  'TYPES_MV' obj from dual)
             ---actual query
    16    select regexp_replace(obj, '^*(_T|_MV)$', '') regexp
    17    from   schema1
    18    minus
    19    select regexp_replace(obj, '^*(_T|_MV)$', '') regexp
    20    from   schema2;
    REGEXP
    OBJECTS
    1 row selected.And vice versa (schema2 minus schema1)

  • Regular Expressions Help in Dreamweaver

    Hi i am using Dreamweaver CS3, i am creating more than 100 HTML files every couple of days and need to use the regular Expressions Feature in the Find and Replace box but couldn't find or generate the expression i am looking For, i want to Replace every images name to be same as it's htm file name across all htm Files.
    Ex : cieg.htm
    <tr>
        <td colspan="2"><table id="Table_04" width="850" height="88" border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td><img src="Viva/XXXthefilenameXXX_38.gif" width="213" height="88"></td>
              <td><img src="Viva/XXXthefilenameXXX_39.gif" width="212" height="88"></td>
              <td><img src="Viva/XXXthefilenameXXX_40.gif" width="213" height="88"></td>
              <td><img src="Viva/XXXthefilenameXXX_41.gif" width="212" height="88"></td>
            </tr>
          </table></td>
      </tr>
    and replace it to be:
    <tr>
        <td colspan="2"><table id="Table_04" width="850" height="88" border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td><img src="Viva/cieg_38.gif" width="213" height="88"></td>
              <td><img src="Viva/cieg_39.gif" width="212" height="88"></td>
              <td><img src="Viva/cieg_40.gif" width="213" height="88"></td>
              <td><img src="Viva/cieg_41.gif" width="212" height="88"></td>
            </tr>
          </table></td>
      </tr>
    and same as another htm file named zsac.htm
    Any one knows a way to do it???
    Regards

    Dreamweaver's Find and Replace can't use the filename automatically. You would need to do it separately for each page. However, the following regular expression should speed up the process on individual pages:
    Find in: Current Document
    Search: Source Code
    Find:
    (<img src="Viva/)[\w]+(\d{2}.gif")
    Replace
    $1cieg_$2
    In other words, you need to add "cieg" or the name of the file between $1 and _$2.
    [Edited by DP to correct error in first sentence. DW cannot use the filename automatically.]

  • Oracle Regular Expressions in Java?

    JDEV 10.1.3
    ADF BC
    ADF Faces
    Is there a Java library for dealing with Oracle regular expressions? I would like to be able to test a String against an Oracle regular expression for pattern match.
    Thank you,

    Hi,
    Java supports RegularEpressions: http://www.exampledepot.com/egs/java.util.regex/pkg.html
    Frank

  • PL/SQL Regular Expression help.

    A'ight, I'm braindead today and cannot figure this out. I have data that can be in following formats:
    format 1: '123 (A XXX)'
    format 2: '123 (A (XXX) Z)'
    format 3: '123 (A (XXX) Z)(B (YYY) Z)'
    Looking for a regular expression that will parse data and return following:
    result 1: '(A XXX)'
    result 2: '(A (XXX) Z)'
    result 3: '(A (XXX) Z)'
    Thanks for your help.

    SQL>l
      1  with t as (
      2  select '123 (A XXX)' col from dual union all
      3  select '123 (A (XXX) Z)' from dual union all
      4  select '123 (A (XXX ) Z)' from dual union all
      5  select '123 (A (XXX) Z )' from dual union all
      6  select '123 (A (XXX) Z)(B (YYY) Z)' from dual union all
      7  select '123 (A (XXX) Z )(B (YYY) Z)' from dual union all
      8  select '123 (A (XXX) Z) (B (YYY) Z)' from dual union all
      9  select '123 (A (XXX) Z ) (B (YYY) Z)' from dual
    10  )
    11  select col, length(col), instr(col, '(') sp, instr(col, ')')-1 ep,
    12  substr( col , instr(col, '(') , instr(col, ')')-1) new_col
    13* from t
    SQL>/
    COL                               LENGTH(COL)               SP               EP NEW_COL
    ============================ ================ ================ ================ ==============================
    123 (A XXX)                                11                5               10 (A XXX)
    123 (A (XXX) Z)                            15                5               11 (A (XXX) Z)
    123 (A (XXX ) Z)                           16                5               12 (A (XXX ) Z)
    123 (A (XXX) Z )                           16                5               11 (A (XXX) Z
    123 (A (XXX) Z)(B (YYY) Z)                 26                5               11 (A (XXX) Z)
    123 (A (XXX) Z )(B (YYY) Z)                27                5               11 (A (XXX) Z
    123 (A (XXX) Z) (B (YYY) Z)                27                5               11 (A (XXX) Z)
    123 (A (XXX) Z ) (B (YYY) Z)               28                5               11 (A (XXX) Z
    8 rows selected.

  • Regular expression help needed

    Hello experts,
    I am looking to implement a search & replace regular expression
    my regular expressions are as follows:
    search regular expression = (test\\s+--\\s*)?this is a test(.*)?
    replace regular expression = (new) brand new test$2
    i.e. The results I require are
    case 1
    input string = test -- this is a test 1999
    correct result = (new) brand new test 1999
    or (since I require the regular expression to be optional)
    case 2
    input string = this is a test
    correct result = brand new test
    How do I implement this using pattern and matcher? Sample code would be useful
    I am having difficulties because matcher.appendReplacement will always replace because my regular expressions are optional. (which is incorrect)
    i.e. I am getting the following incorrect result ((new) is being appended)
    input string = this is a test
    incorrect result = (new) brand new test
    At the moment my non working code is
    StringBuffer sb = new StringBuffer();
    Pattern pattern = Pattern.compile("(test\s+--\s*)?this is a test(.*)?");
    Matcher matcher = pattern.matcher("this is a test");
    if(matcher.find())
    matcher.appendReplacement(sb, "(new) brand new test$2");
    String result = sb.toString();
    System.out.println(result);
    }In the above scenario I want the output to be 'brand new test' without the (new) because the input string did not contain 'test --'
    Hope this makes sense
    Thanks

    For example: StringBuffer sb = new StringBuffer();
    Pattern pattern = Pattern.compile("(test\s+--\s*)?this is a test(.*)");
    Matcher matcher = pattern.matcher("this is a test");
    if(matcher.find())
      matcher.appendReplacement(sb, ""); // copy everything before the match
      if (matcher.start(1) != -1)
        sb.append("(new) ");
      sb.append("brand new test");
      sb.append(matcher.group(2));
    matcher.appendTail(sb); // copy everything after the match
    System.out.println(sb.toString()); Because the first group is optional, you need to find out whether it participated in the match before you add the "(new) " bit. The second group doesn't need to be optional because (1) the subexpression with the group can match nothing, and (2) you don't need to perform a different action depending on what that group did. You just append the captured text, which may be an empty string.

  • Regular Expressions help needed.

    Hi,
    I have lines like
              <div id="contentSub">         26
              /*]]>*/</style>         27
    <ul>         30
    Dylan is gay         36
    var wgNamespaceNumber = 0;         41You see every line is contained a string plus some white spaces then plus a number.
    How to retrieve the strings?
    Such that becomes
    <div id="contentSub">
              /*]]>*/</style>
    <ul>  
    Dylan is gay   
    var wgNamespaceNumber = 0;  And also get the number by a regular expression
    26
    27
    30
    36
    41Thanks

    I believe that
    "^(.*)\\s+(\\d+)$"would do the trick. Pick the two groups out from the Matcher.

  • Regular Expression help needed plzzz

    Hi,
    I am trying to form a regular expression in order to search for say two char patterns and both the patterns should be present. Say I have a string example = "ModeleerComponent.java,1.1"I am using a regular expression to find whether the user input matches with it or not. For example the user can enter Mod and 1.1...now since the string contains Mod and 1.1 the result should be true.
    This is how my regular expression looks regex = ^(?=.*?Mod)(?=.*?1\.1).*$ so now the result is true is okay. But if I enter code]regex = ^(?=.*?asdfg)(?=.*?1\.1).*$ it should return false but it returns true. As 1.1 is present. Could someone tell me how I could use an AND that is when both Mod and 1.1 are present then only return true.
    I hope whatever I have written is understandable.
    Thank you very much.

    Or this:
    public class TestRegex {
        public static void main(String[] args) {
                String example = "ModeleerComponent.java,1.1";
                System.out.println(example.indexOf("Mod") != -1 && example.indexOf("1.1") != -1);
    }returns:
    true

  • Regular Expression Help Needed - Thanks

    Hi
    Can someone please tell me how to the regex to search for the a world not preceded by another word.
    ex. search for the word "Hardcover" NOT preceded by the word "Not"
    ... Hardcover ... -> OK
    ... Not Hardcover ... -> BAD, because there's a "Not" before "Hardcover"
    thanks

    Use negative lookbehind:   Pattern p = Pattern.compile("(?<!Not )Hardcover");http://www.regular-expressions.info/

  • Regular Expression help required

    {color:#000000}Hi....
    I am having a product table in oracle with products like CZS20T and CZSS30T and so on....
    But for printing on the invoice we need only the product name without the micron thickness like CZS and CZSS{color}{color:#000000}
    I tried regular expression with....."select regexp_substr('CZSS20T','([[:digit:]]{2})') from dual"
    {color}
    and the result was "20"*...*
    But I cant figure out how to use regular expression to get only the product name.
    Maybe there is another way without using Regular exp...
    Please help....

    regexp_substr (prod, '[[:alpha:]]*')and an example:
    SQL> with x as
      2  ( select 'CZS20T' prod from dual union all
      3    select 'CZSS30T' from dual union all
      4    select 'A10CSD' from dual
      5  )
      6  select prod
      7       , regexp_substr (prod, '[[:alpha:]]*')
      8    from x
      9  ; 
    PROD    REGEXP_SUBSTR(PROD,'[[:ALPHA
    CZS20T  CZS
    CZSS30T CZSS
    A10CSD  A
    SQL> Edited by: Alex Nuijten on Jan 27, 2009 8:52 AM

  • Regular Expression Help

    I need help writting a regular expression that will match the following strings:
    1+1,1+(1+1),((1+1)+(1+1)),1+(1+(1+1)). Basically one that will match an arithmetic expression (operands limited to 1's and operators to '+' sign) with or without correctly matched parentheses. Have'nt had much luck so far. Any input will help. thanks

    okay, you asked for it:
    [1+()]+
    it will only match those string but it will tell you nothing about syntactically correct expressions. This is because these types of expression are not "regular" and cannot be properly parsed using regular expressions.

  • Regular expression help to solve sys_refcursor for a record

    In reference to my thread Question on sys_refcursor with record type , I thought it can be solved differently. That is:
    I have a string like '8:1706,1194,1817~1:1217,1613,1215,1250'
    I need to do some manipulation using regular expressions and acheive some thing like
    select * from <table> where
    c1 in (8,1)
    and c2 in (1706,1194,1817,1217,1613,1215,1250);Is it possible using regular expressions in a single select statement?

    Hi,
    Clearance 6`- 8`` wrote:
    Your understanding is absolutely correct. But unfortunately it did not work Frank.
    SQL> SELECT COUNT (*)
    2    FROM (SELECT sp.*
    3            FROM spml sp, spml_assignment spag
    4           WHERE sp.spml_id = spag.spml_id
    5             AND spag.class_of_svc_id = 8
    6             AND spag.service_type_id IN (1706, 1194, 1817)
    7             AND spag.carrier_id = 4445
    8             AND NVL (spag.haulage_type_id, -1) = NVL (NULL, -1)
    9             AND spag.effdate = TO_DATE ('01/01/2000', 'mm/dd/yyyy')
    10             AND spag.unit_id = 5
    11             AND sales_org_id = 1
    12          UNION ALL
    13          SELECT sp.*
    14            FROM spml sp, spml_assignment spag
    15           WHERE sp.spml_id = spag.spml_id
    16             AND spag.class_of_svc_id = 1
    17             AND spag.service_type_id IN (1217, 1613, 1215, 1250)
    18             AND spag.carrier_id = 4445
    19             AND NVL (spag.haulage_type_id, -1) = NVL (NULL, -1)
    20             AND spag.effdate = TO_DATE ('01/01/2000', 'mm/dd/yyyy')
    21             AND spag.unit_id = 5
    22             AND sales_org_id = 1);
    COUNT(*)
    88
    SQL> SELECT COUNT (*)
    2    FROM spml sp, spml_assignment spag
    3   WHERE sp.spml_id = spag.spml_id
    4     AND spag.carrier_id = 4445
    5     AND NVL (spag.haulage_type_id, -1) = NVL (NULL, -1)
    6     AND spag.effdate = TO_DATE ('01/01/2000', 'mm/dd/yyyy')
    7     AND spag.unit_id = 5
    8     AND sales_org_id = 1
    9     AND REGEXP_LIKE ('8:1706,1194,1817~1:1217,1613,1215,1250',
    10                      '(^|~)' || spag.class_of_svc_id || ':'
    11                     )
    12     AND REGEXP_LIKE ('8:1706,1194,1817~1:1217,1613,1215,1250',
    13                      '(:|,)' || spag.service_type_id || '(,|$)'
    14                     );
    COUNT(*)
    140
    SQL> Edited by: Clearance 6`- 8`` on Aug 11, 2009 8:04 PMJust serving what you ordered!
    Originally, you said you were looking for something that produced the same result as
    where   c1 in (8, 1)
    and      c2 in (1706, 1194, 1817, 1217, 1613, 1215, 1250)that is, any of the c1s could be paired with any of the c2s.
    Now it looks like what you want is
    where     (     c1 = 8
         and     c2 IN (1706, 1194, 1817)
    or     (     c1 = 1
         and     c2 IN (1217, 1613, 1215, 1250)
         )that is, c1=8 and c2=1250 is no good; neither is c1=1 and c2=1706.
    In that case, try
    WHERE     REGEXP_LIKE ( s
                  , '(^|~)' || c1
                         || ':([0-9]+,)*'
                         || c2
                         || '(,|~|$)'
                  )

  • Java Regular Expression -- Help

    Hello All,
    I am looking for a regular condition matching the following conditions: -
    The input String should contain at least [A-Z]+ and [0-9]+ and any other characters. Basically the word should have one Capital character and and one number (any where in the input string) and any other characters.
    If someone can help me, I would appreciate all your help. Thanks in advance.
    Raj

    twizzle wrote:
    DarrylBurke wrote:Not such a monster ;-)"(.*[A-Z].*[0-9].*)|(.*[0-9].*[A-Z].*)"{code}What if I need a single RE to express that my string must contain a capital letter, a lower-case letter, a digit, a punctuation mark ([.,!?;:]) and a whitespace character (\s), in whatever order? :P
    DavidNo problem, using positive look ahead, you don't have to use those OR's:
    "^(?=.*[A-Z])(?=.*[a-z])(?=.*\\d)(?=.*[.,!?;:])(?=.*\\s).*$"

  • Regular Expression Help Please?

    Hi
    I'm trying to get my head round regular expressions in find
    and replace,
    it's a slow process for me!
    I have this -
    <a
    href="
    http://www.forms.mydomainname.com/cgi-bin/urltracker/tracker.pl?site=http://www.website-ad dress.com"
    and I'm trying to change it to this -
    <a
    href="
    http://www.forms.mydomainname.com/cgi-bin/urltracker/tracker.pl?site=http://www.website-ad dress.com&email="
    I was trying first of all with a *.*, but couldn't work out
    how to tell it
    where the code ends?
    They are hundred of pages like this, all with different
    website-addresses.
    After I have changed all the pages to the new code, I then
    will need to copy
    and paste an different email address to the end of each line,
    to each page.
    Unless anyone knows a way of automating that?
    Hope someone can point me in the right direction?
    Many thanks, Craig.

    Hi David
    Many thanks for all that and the detailed descriptions.
    I will be working through it all again tomorrow, so will put
    your info to
    the test! lol
    As for partially building the email addresses, I think that
    would be too
    much,
    as the emails are all over the place, some have their own
    domain, other use
    hotmail, Yahoo etc.
    Some even have they own domain for their website and a free
    one for the
    email address.
    They are all Hotels, B&B' & Cottages etc.
    Hopefully all your hard work will help me a step closer to
    understanding it
    all.
    Many thanks again,
    Craig.
    "David Stiller" <[email protected]> wrote in
    message
    news:[email protected]...
    > Craig,
    >
    >> You do have that correct David, thanks.
    >
    > Okay.
    Regex is as much an "exact science" as it is an "art
    > form" -- which isn't to say I'm a regex artist; I just
    love the
    > technology -- but I mention this because I made the
    following assumption
    > in order to keep the pattern relatively simple: your
    href values are all
    > quoted in either single or double quotes. Such as, for
    example, the
    > following sample HTML ...
    >
    > <body>
    > <a
    > href="
    http://www.forms.mydomainname.com/cgi-bin/urltracker/tracker.pl?site=www.sample.com">asfd< /a>
    > <a
    > href='
    http://www.forms.mydomainname.com/cgi-bin/urltracker/tracker.pl?site=www.example.net'></a>
    > <a
    > href="
    http://www.forms.mydomainname.com/cgi-bin/urltracker/tracker.pl?site=www.company.com"></a>
    > </body>
    >
    > In the Find field, enter this pattern ...
    >
    > (tracker\.pl\?site=.*?)(["'])
    >
    > ... and in the Replace field, enter this pattern ...
    >
    > $1&email=ADDRESS$2
    >
    > Then carefully use your Find Next and Replace buttons to
    step through
    > your code. The above will add &email=ADDRESS to your
    HTML in all the
    > right places. I chose that because ADDRESS is easy to
    select by double
    > clicking, which should facilitate your replacing it.
    >
    >
    > Let's step through the patterns.
    >
    > (tracker\.pl\?site=[^"']*?)(["'])
    >
    > This looks for the phrase "tracker.pl?site=" (without
    quotes) followed
    > immediately by a "non-greedy" match of any character
    that isn't a single
    > or double quotation mark, followed immediately by either
    a single or
    > double quotation mark. I took , which I took to be a
    safe, short "hook"
    > into the string we need. I split this pattern into two
    sections, grouped
    > by parentheses. This allows us to refer to the first
    part of the match
    > (everything but the closing quotation mark) as group 1,
    and the second
    > part (the closing quotatin mark) as group 2. This is
    like storying values
    > with your calculator's M (memory) button.
    >
    > $1&email=ADDRESS$2
    >
    > Here, we refer to group 1 and follow it with the phrase
    > "&email=ADDRESS" (without quotes), followed again by
    group 2.
    >
    > Now, in theory, we could use the domain name of each
    unique site to at
    > least partially build the email address. That would get
    you even closer
    > to your goal. To do so, I'd need even more detail from
    you, such as the
    > kinds of domains you have (how many sub domains are
    probable, etc.).
    >
    >
    > David
    > stiller (at) quip (dot) net
    > Dev essays:
    http://www.quip.net/blog/
    > "Luck is the residue of good design."
    >

  • Regular expressions help

    I'm using a RegExp class (http://www.jurjans.lv/flash/RegExp.html) to do some regular expression in AS2. But I'm not very good at it.
    var str:String="What if there are other variables, such as possible <a class='gloss' href='asfunction:_root.handle, confounding variables'><b>confounding variables</b></a> which could explain at least some of the relationship between the two variables? Here <a href='' target='_blank'>is another link</a>.\n<a class='gloss' href='asfunction:_root.handle, confounding variables'>confounded variables</a>"
    var reg1:RegExp = new RegExp("<a.*gloss.*href=[\'\"]?([^\\\'\">]+)>+(.*</a>)", "ig");
    var obj:Object = reg1.exec(str);
    while (obj != null) {
              for(var a in obj){
                        if(!isNaN(a)){
                        trace(a+": "+obj[a]);
              trace(newline);
              obj = reg1.exec(str);
    And this traces:
    2: <b>confounding variables</b></a>
    1: asfunction:_root.handle, confounding variables'
    0: <a class='gloss' href='asfunction:_root.handle, confounding variables'><b>confounding variables</b></a>
    2: confounded variables</a>
    1: asfunction:_root.handle, confounding variables'
    0: <a class='gloss' href='asfunction:_root.handle, confounding variables'>confounded variables</a>
    I'm trying to get the href and the "friendly link" part of the anchor tag (but only for anchors that have a class of gloss).
    As you can see I'm almost there, but I'm getting the extra </a> and the extra ' on the two examples. I tried putting the ) before the </a> but that just broke it. (Of course that could be because this class doesn't work properly, but I'm guessing that isn't the case.)
    Anybody really good with regular expressions who can help me out?

    Looks like there is a "greedy" bug with the () in that AS2 implementation.
    I also have a problem the expression matching not the next occurance of the closing </a> but the final one.
    Anybody have any ideas of other ways to do this?

Maybe you are looking for

  • Acrobat Shared Review: Access Denied?

    One of the guys on our network is on a Mac, the other two on PCs, and we all have Adobe Acrobat Pro 9. He is trying to send out a shared review, but whenever we click the link to the review in the "Please join this shared review" email, we get a popu

  • I am going crazy

    a few months ago my mac mail program went crazy. first it kept asking for keychain access password then it stopped allowing me to send mail. i reinstalled, reconfigured, things seemed to work for a few weeks then boom i can no longer send mail. nothi

  • Gray border/frame around layer when dragging

    Hi all, i've got a very annoying thing going on here. And i'm not able to get rid of it. I use Photoshop CS5 recently and suddenly there is a gray border around my layer when i want to move/drag it. It doesn't matter if it's a shape, raster layer or

  • Transferring from PC to iMac?

    Hello, I wanted to know if anyone can explain how to get all my old various email from Microsoft Outlook 2007 to my new iMac? I have lots of old emails that I need to keep for future reference? There are to many to re email to myself too! Also I need

  • Dashboard Reports in B1

    Hi All,        My client is asking dashboard reports, they need it in all the project managers desktop. The report should be in flash technology.        Please help me anyone...