Help with Regular Expressions and regexp_replace

Oh great Oracle Guru can I can gets some help
I need to clean up the phone numbers that have been entered in Oracle eBusiness per_phones table. Some of the phone numbers have dashes, some have spaces and some have char. I would just like to take all the digits out and then re-format the number.
Ex.
914-123-1234 .. output (914) 123-1234
9141231234 ..again (914) 123-1234
914 123 1234 .. (914) 123-1234
myphone ... just null
(914)-123-1234.. (914) 123-1234
I really tried to understand the regular expressions statments, but for some reason I just can't understand it.

Hi,
Welcome to the forum!
I would create a user-defined function for this. I expect there will be a lot of exceptions to the regular rules (for example, strings that do not contain exactly 10 digits, such as '1-800-987-6543') that can be handled, but would require lots of nested fucntions and othwer complicted code if you had to do it in a single statement.
If you really want to do it with a regular expression:
SELECT     phone_txt
,     REGEXP_REPLACE ( phone_txt
                 , '^\D*'          || -- 0 or more non-digits at the beginning of the string
                       '(\d\d\d)'     || -- \1 = 3 consecutive digits
                '\D*'          || -- 0 or more non-digits
                       '(\d\d\d)'     || -- \2 = 3 consecutive digits
                '\D*'          || -- 0 or more non-digits
                       '(\d\d\d)'     || -- \3 = 4 consecutive digits
                '\D*$'             -- 0 or more non-digits at the end of the string
                 , '(\1) \2-\3'
                 )          AS new_phone_txt
FROM    table_x
;

Similar Messages

  • Assistance with Regular Expression and Tcl

    Assistance with Regular Expression and Tcl
    Hello Everyone,
      I recently began learning Tcl to develop scripts for automating network switch deployments. 
    In my script, I want to name the device with a location and the last three octets of the base mac address.
    I can get the Base MAC address by : 
    show version | include Base
     Base ethernet MAC Address       : 00:00:00:DB:CE:00
    And I can get the last three octets of the MAC address using the following regular expression. 
    ([0-9a-f]{2}[:-]){2}([0-9a-f]{2}$)
    But I have not been able to figure out how to call the regular expression in the tcl script.
    I have checked several resources but have not been able to figure it out.  Suggestions?
    Ultimately, I want to set the last three octets to a variable (something like below) and then call the variable when I name the switch.
    set mac [exec "sh version | i Base"] (include the regular expression)
    ios_config "hostname location$mac"
    Thanks for any assistance in advance.
    Chris

    This worked for me.
    Switch_1(tcl)#set result [exec show ver | inc Base]   
    Base ethernet MAC Address       : 00:1B:D4:F8:B1:80
    Switch_1(tcl)#regexp {([0-9A-F:]{8}\r)} $result -> mac
    1
    Switch_1(tcl)#puts $mac                               
    F8:B1:80
    Switch_1(tcl)#ios_config "hostname location$mac"      
    %Warning! Hostname should contain at least one alphabet or '-' or '_' character
    locationF8:B1:80(tcl)#

  • Help with Regular Expression for field validation

    I'm fairly new to using regular expressions and using Acrobat. This is probably a simple question, but I've been unable to figure it out.
    I have a text field on a PDF that I would like to be 9 characters in length. The first 2 characters can only be alphanumeric, the last 7 characters can only be numeric.
    At first I was using the following, which allows all the characters to be alphanumeric:
    var re = /^[A-Za-z0-9 :\\_]$/;
    if (event.change.length >0) {
    if (event.willCommit == false) {
        if (!re.test(event.change)) {
            event.rc = false
    That works fine, but it's not quite what I needed. With some assistance I changed it (see below) to fit what I was looking for. However, this didn't work; it prevents anything from being entered in the field:
    var re = /^[A-Za-z0-9]{2}\d{7}$/;
    if (event.change.length >0) {
    if (event.willCommit == false) {
        if (!re.test(event.change)) {
            event.rc = false
    Any help would be greatly appreciated.
    Thanks...

    Here's a function you can call form the field's custom Format script. It should be placed in a document-level JavaScript:
    function custom_ks1() {
        // Define non-commited regular expression
        var re = /^[A-Za-z0-9]{0,2}([0-9]{0,7})?$/;
        // Get all of the characters the user has entered
        var value = AFMergeChange(event);
        // Allow field to be cleared
        if(!value) return;
        if (event.willCommit) {
            // Define commited regular expression
            var re = /^[A-Za-z0-9]{2}[0-9]{7}$/;
            if (!re.test(value)) {  // If final value doesn't match, alert user
                app.alert("Your error message goes here.");
                // event.rc = false
        } else {  // not commited
            // Only allow characters that match the regular expression
            event.rc = re.test(value);
    Call it like this:
    // Custom Keystroke script
    custom1_ks();

  • Need help with regular expression

    I'm trying to use the java.util.regex package to extract URLs from html files.
    The URLs that I am interested in extracting from the HTML look like the following:
    <font color="#008000">http://forum.java.sun.com -
    So, the URL is always preceeded by:
    <font color="#008000">
    and then followed by a space character and then a hyphen character. I want to be able to put all these URLs in a Vector object. This doesn't seem like it should be too difficult but for some reason I can't get anywhere with it. Any help would be greatly appreciated. Thanks!

    hi gupta am not sure of the java syntax but i can tell u about the regular expression...try this....
    <font color="#008000">(http:\/\/[a-zA-Z0-9.]+) [-]
    i dont know the java methods to call...just the reg exp...
    Sanjay Acharya

  • Help with regular expression needed

    Hi,
    Perhaps someone here can help me with my regular expression I'm trying to build in my Java code.
    The regular expression that I'm looking to build consists of any non-whitespace character up until it finds one or two <>= symbols and then any character thereafter. So both these Strings would match the expression:
    City 1==London
    Age>=18
    The regular expression that I'm using is as follows:
    (\\S+)([><=]){1,2}(.+)However, group 1 always retrieves the first <>= symbol as in "City 1=". How can I make the <>= part greedy so that it retrieves both operator symbols?
    Thanks.

    Make the first group, the non-spaces, reluctant:
    "(\\S+?)([<>=]{1,2})(.+)"

  • Help with regular expression to find a pattern in clob

    can someone help me writing a regular expression to query a clob that containts xml type data?
    query to find multiple occurrences of a variable string (i.e <EMPID-XX> - XX can be any number). If <EMPID-01> appears twice in the clob i want the result as EMPID-01,2 and if EMPID-02 appears 4 times i want the result as EMPID-02,4.

    with
    ofx_clob as
    (select q'~
    <EMPID>1
    < UNQID>123456
    < TIMESTAMP>...
    < ADDRINFO>
    < TITLE>^@~*
    < FIRST>ABCD
    < MI>
    < LAST>EFGH
    < ADDR1>ADDR1
    < ADDR2>^@~*
    < CITY>CITY
    <EMPID>2
    < UNQID>123457
    < TIMESTAMP>...
    < ADDRINFO>
    < TITLE>^@~*
    < FIRST>ABCD
    < MI>
    < LAST>EFGH
    < ADDR1>ADDR1
    < ADDR2>^@~*
    < CITY>CITY
    <EMPID>1
    < UNQID>123458
    < TIMESTAMP>...
    < ADDRINFO>
    < TITLE>^@~*
    < FIRST>ABCD
    < MI>
    < LAST>EFGH
    < ADDR1>ADDR1
    < ADDR2>^@~*
    < CITY>CITY
    ~' ofx from dual
    select '<EMPID>' || to_char(ids) || '(' || to_char(count(*)) || ')' multi_empid
      from (select replace(regexp_substr(ofx,'<EMPID>\d*',1,level),'<EMPID>') ids
              from ofx_clob
            connect by level <= regexp_count(ofx,'<EMPID>')
    group by ids having count(*) > 1
    MULTI_EMPID
    <EMPID>1(2)
    with
    ofx_clob as
    (select q'~
    <EMPID>1
    < UNQID>123456
    < TIMESTAMP>...
    < ADDRINFO>
    < TITLE>^@~*
    < FIRST>ABCD
    < MI>
    < LAST>EFGH
    < ADDR1>ADDR1
    < ADDR2>^@~*
    < CITY>CITY
    <EMPID>2
    < UNQID>123457
    < TIMESTAMP>...
    < ADDRINFO>
    < TITLE>^@~*
    < FIRST>ABCD
    < MI>
    < LAST>EFGH
    < ADDR1>ADDR1
    < ADDR2>^@~*
    < CITY>CITY
    <EMPID>1
    < UNQID>123456
    < TIMESTAMP>...
    < ADDRINFO>
    < TITLE>^@~*
    < FIRST>ABCD
    < MI>
    < LAST>EFGH
    < ADDR1>ADDR1
    < ADDR2>^@~*
    < CITY>CITY
    <EMPID>2
    < UNQID>123456
    < TIMESTAMP>...
    < ADDRINFO>
    < TITLE>^@~*
    < FIRST>ABCD
    < MI>
    < LAST>EFGH
    < ADDR1>ADDR1
    < ADDR2>^@~*
    < CITY>CITY
    <EMPID>1
    < UNQID>123458
    < TIMESTAMP>...
    < ADDRINFO>
    < TITLE>^@~*
    < FIRST>ABCD
    < MI>
    < LAST>EFGH
    < ADDR1>ADDR1
    < ADDR2>^@~*
    < CITY>CITY
    ~' ofx from dual
    select '<EMPID>' || listagg(to_char(ids) || '(' || to_char(count(*)) || ')',',') within group (order by ids) multi_empid
      from (select replace(regexp_substr(ofx,'<EMPID>\d*',1,level),'<EMPID>') ids
              from ofx_clob
            connect by level <= regexp_count(ofx,'<EMPID>')
    group by ids having count(*) > 1
    MULTI_EMPID
    <EMPID>1(3),2(2)
    Regards
    Etbin
    Message was edited by: Etbin
    used listagg to report more than one multiple <EMPID>

  • Help With Regular Expression In Apex Validation

    Apex 3.2
    There is a validation type of regular expression in apex, but I have never used regular expression before,
    so a little help is appreciated.
    I need to validate a field. It is only allowed to contain alpha characers, numbers, spaces and the - (dash) character.
    I have tried several times to get this working
    eg
    [[:alpha:]]*[[:digit:]]*[[:space:]]*[-]*
    ^[[:alpha:][:digit:][:space:]-]+?
    and others, but just can't to get the syntax correct.
    Can someone help me with this please
    Gus

    Example:
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select 'This is some example text' as txt from dual union all
      2             select 'And this is the 2nd one with numbers' from dual union all
      3             select 'And this allows double-barrelled words with hyphens' from dual union all
      4             select 'But this one shouldn''t be allowed!' from dual
      5            )
      6  --
      7  select *
      8  from t
      9* where regexp_like(txt, '^[[:alnum:] -]*$')
    SQL> /
    TXT
    This is some example text
    And this is the 2nd one with numbers
    And this allows double-barrelled words with hyphens

  • Need help with Airport Express and so on.

    Ok so my main problem before getting into what I need help with here is that our MacBooks and now my iPhone 6 plus isn't staying online. Keep getting booted off and then I either have to select the network again or it will eventually go back on. If anyone has a solution or so please feel free to answer that as well. I'm running on Roadrunner with a Netgear 600 wireless router and a motorola modem. Both of which I'll leave the link to below for a better look.
    My Main Question: So I'm looking at a new wireless router mainly and possibly a new modem. I know Apple products are trustworthy but how good is the Airport Express and other Airport products. Also what is the Maximum speed and Maximum data speed for the cheapest express station and if anyone knows the speeds of the other devices it would be greatly appreciated.

    DSL Router to Netgear 5-port Switch and I used the switch to connect to Airport Extreme, TV, Blue-Ray DVD player and DirecTV Receiver.
    The AirPort Extreme base station (AEBS) is a router so it will do what you need.
    You need to reconfigure your setup. Connect the WAN port of the AEBS to the DSL router. Then connect the Netgear switch to one of the LAN ports on the AEBS. The AEBS will properly share the connection.

  • Help with Regular Expressions

    I have some sample code for string editing using regular expressions but I'm a little confused as to it's behavior. Here's what I have:
    public class WordFixer
        protected final String PUNC_MATCH = "[\\d\\p{Punct}]+";
        protected final String PUNC_PREFIX = "^" + PUNC_MATCH;
        protected final String PUNC_SUFFIX = PUNC_MATCH + "$";
        public String fixPrefix (String w)
            return w.replaceFirst(PUNC_PREFIX, "");
        public String fixSuffix (String w)
            return w.replaceFirst(PUNC_SUFFIX, "");
        }This replaces all leading and trailing punctuation with "" and it works. However, changing the replaceFirst's to just replace doesn't work. I don't understand why that is. Doesn't the ^ mean in the front, and doesn't the $ mean in the back, so shouldn't this work by just changing replaceFirst to replace?

    JFactor2004 wrote:
    I have some sample code for string editing using regular expressions but I'm a little confused as to it's behavior. Here's what I have:
    public class WordFixer
    protected final String PUNC_MATCH = "[\\d\\p{Punct}]+";
    protected final String PUNC_PREFIX = "^" + PUNC_MATCH;
    protected final String PUNC_SUFFIX = PUNC_MATCH + "$";
    public String fixPrefix (String w)
    return w.replaceFirst(PUNC_PREFIX, "");
    public String fixSuffix (String w)
    return w.replaceFirst(PUNC_SUFFIX, "");
    }This replaces all leading and trailing punctuation with "" and it works. However, changing the replaceFirst's to just replace doesn't work. I don't understand why that is. The first parameter of the replaceFirst(...) is a regex-String. And the ^, $ and [...] stuff all have a special meaning in the regex language. The replace(...) method takes plain-Strings as a parameter, so the String "^\[\\d\\p{Punct}\]+" is interpreted as just that, without any special meaning.
    JFactor2004 wrote:
    Doesn't the ^ mean in the front, and doesn't the $ mean in the back, Yes, ^ means the start of the String (sometimes the start of a line) and $ means the end of the String (sometimes the end of a line).
    JFactor2004 wrote:
    so shouldn't this work by just changing replaceFirst to replace?Nope, see the explanation above.

  • Litte help with regular expression?

    Greetings all,
    I have a simple regular expression "(\\w+)\\s(\\w+)\\s(.+)"
    Which I want to match against the strings like "Acetobacter pasteurianus LMD22.1"
    But this always fails whenever there is a dot (.) character like "LMD22.1" in above string.
    How to solve this ?
    Thanks in advance.

    Shouldn't that be Acinetobacter?
    edit: nope, I'm wrong, you're right.
    Edited by: Encephalopathic on Apr 7, 2009 7:34 PM

  • Help with regular expression to not run shtml-hacktype on particular reqs

    Hi,
    Okay, back to 7.0 u2 not ignoring things it should. Our regular site has a lot of SHTML includes. Then we have the glassfish loadbalancer plugin configured for a back-end web application. The problem is, the application URLs end in .html and the web server is looking locally for those requests. If I disable:
    ObjectType fn="shtml-hacktype"In the instance obj.conf, then the requests process normally in the proxy.
    I can't do that, though, because of the includes - then our main site doesn't function properly.
    Is there a way I can surround that line with something like "if request is not /gog/*" then execute? Similar to what I had to do for the j2ee problem looking locally instead of on the back end Weblogic servers.
    <If $uri =~ '^/wp-(.*)'>
    NameTrans fn="ntrans-j2ee" name="j2ee"
    </If>Only I want the opposite - if $uri is not equal to '^/gog/(.*)' then execute the shtml hacktype. I just don't know exactly what the expression would be.
    Thanks!

    Nevermind - I got it. RTFM :-)
    <If $uri !~ '^/gog/(.*)'>
    ObjectType fn="shtml-hacktype"
    </If>

  • Need help on Regular expression and query

    Hi Guru's, Hope you all are doing great!.
    I have a scenario's where i need do insert the data into table.
    I have three scenarios :
    select 'Kodali,Raj,S' str from dual
    union
    select 'Alex Romano' from dual
    union
    select 'ppppp' from dual
    Alex Romano
    Kodali,Raj,S
    pppppNow what i want is .
    1. Alex Romano
    if there is space between the string then i want to insert into first name and last name columns
    2. Kodali,Raj,S
    if its a comma between the string then i want to insert into last name , first name and middle name
    3. if there is only one string then same insert into first name and last name.
    I wrote the query earlier to handle only comma and now i am trying but not able to use this all scenarios
    Can you please help me out.
    WITH t AS (
    select 'Kodali,Raj,S' str from dual
    union
    select 'Alex Romano' from dual
    union
    select 'ppppp' from dual
    select DECODE(trim(a),NULL,'a',trim(a)),DECODE(trim(b),NULL,'b',trim(b)),decode(trim(c),NULL,'c' ,trim(c))
    from
      SELECT max(decode(level,1,regexp_substr(str,'[^,]+',1,level))) a --INTO lFNAME
              , max(decode(level,2,regexp_substr(str,'[^,]+',1,level))) b --INTO lLNAME
              , max(decode(level,3,regexp_substr(str,'[^,]+',1,level))) c --INTO lMNAME      
       FROM   t
      CONNECT BY regexp_substr(str,'[^,]+',1,level) IS NOT NULL
      GROUP BY str
    ) ;Currently i am putting a b and c if its null.
    Thanks in advance!

    user590978 wrote:
    Hi Guru's, Hope you all are doing great!.
    I have a scenario's where i need do insert the data into table.
    I have three scenarios :
    select 'Kodali,Raj,S' str from dual
    union
    select 'Alex Romano' from dual
    union
    select 'ppppp' from dual
    Alex Romano
    Kodali,Raj,S
    pppppNow what i want is .
    1. Alex Romano
    if there is space between the string then i want to insert into first name and last name columns
    2. Kodali,Raj,S
    if its a comma between the string then i want to insert into last name , first name and middle name
    3. if there is only one string then same insert into first name and last name.
    I wrote the query earlier to handle only comma and now i am trying but not able to use this all scenarios
    Can you please help me out.
    WITH t AS (
    select 'Kodali,Raj,S' str from dual
    union
    select 'Alex Romano' from dual
    union
    select 'ppppp' from dual
    select DECODE(trim(a),NULL,'a',trim(a)),DECODE(trim(b),NULL,'b',trim(b)),decode(trim(c),NULL,'c' ,trim(c))
    from
    SELECT max(decode(level,1,regexp_substr(str,'[^,]+',1,level))) a --INTO lFNAME
    , max(decode(level,2,regexp_substr(str,'[^,]+',1,level))) b --INTO lLNAME
    , max(decode(level,3,regexp_substr(str,'[^,]+',1,level))) c --INTO lMNAME      
    FROM   t
    CONNECT BY regexp_substr(str,'[^,]+',1,level) IS NOT NULL
    GROUP BY str
    ) ;Currently i am putting a b and c if its null.
    Thanks in advance!It's never a popular suggestion, but why not fix the design to begin with?
    It's the year 2013, can a client not pass you a "complex" data structure consisting of first, middle and last name?
    Why rely on an unreliable construct when there are so many more usable way to achieve this?
    Cheers,

  • Please help with regular expression

    Hello,
    With the help of my previous posting answers, Re: Procedure to Extract multiple substring from a string , I updated the query. But, I am not getting desired answer in all case. Could you please help me out? My query is based on the previous posting. Any other simple way to achieve this?
    I will really appreciate it.
    select
           ltrim ( regexp_substr(txt, '\[(\w+)', 1, level), '[')      as id, /* id is number */
           ltrim ( regexp_substr(ltrim ( regexp_substr(txt, ':[^]]+', 1, level), ':'), '\w+-*\d*', 1, 1), ':')  as qid, /* Qid could be char/number/space any combination except ':' */
           ltrim ( regexp_substr(ltrim ( regexp_substr(txt, ':[^]]+', 1, level), ':'), '\w+', 1, 2), ':')      as num,
          to_date( ltrim ( regexp_substr(ltrim ( regexp_substr(txt, ':[^]]+', 1, level), ':'), '[^:]+', 1, 3), ':'),'MM/DD/YY')   as effdate
    from  (
                            select  '[10946:M100:N:][10947:Q1222:N:][38198:PPP-2:N:][13935:PPP-6:N:][38244:QQQ-4:Y:01/01/10]'     as txt
                            from     dual
            connect by level <= length(regexp_replace(txt, '[^[]'));I should get :
    ID             QID          NUM         EFFDATE
    10946     M100     N     
    10947     Q1222     N     
    38198     PPP-2     N     
    13935     PPP-6     N     
    38244     QQQ-4     Y     01-JAN-10But, getting
    ID             QID          NUM          EFFDATE
    10946     M100     N     
    10947     Q1222     N     
    38198     PPP-2     2     
    13935     PPP-6     6     
    38244     QQQ-4     4     01-JAN-10Thanks,

    Hi,
    So the num column is wrong, is that it?
    Describe what the num column should be. For example "num is the 3rd part of the :-delimited list enclosed in the square brackets".
    If that's what you want, then change the definition of num from
    ...                     ltrim ( regexp_substr(ltrim ( regexp_substr(txt, ':[^]]+', 1, level), ':'), '\w+', 1, 2), ':')      as num,to
    ...                      REGEXP_SUBSTR  ( REGEXP_SUBSTR ( txt
                                          , '[^]]+'
                                                , 1
                                       , LEVEL
                             , '[^:]+'
                             , 1
                             , 3
                             )       AS num,

  • Help with regular expression

    we are currently using this below regex for a date field ,
    ^\d\d/\d\d/\d\d\d\d$ now i have to modify this or put in a new regex to accept 00 for date and month
    Now
    00/23/1985 or 23/00/1985 - gives error
    i want to modify this regex so that
    00/00/1985 or 00/12/1985 or 12/00/1985 does not give error.
    thanks :)

    What am I missing?
           String pattern = "^\\d\\d/\\d\\d/\\d\\d\\d\\d$";
            System.out.println("00/23/1985".matches(pattern));
    as expected returns 'true'.

  • Need help with Regular Expressions

    This is my XML code
    *<name>J. E. O'Rrrrrr, S. Mmmmmmmmmm, B. G. Mmmmmmmm, A. B. C. Xxxxxx Yyyyy, A. B. C. Zzzz and C. R. McCcccc</name>*
    This is my source code
    Regex = Pattern.compile("<name>.*?</name>");
    RegexMatcher = Regex.matcher(fetchWholeFile);
    while(RegexMatcher.find())
    chkEnty = RegexMatcher.group();
    Pattern RegexTry1 = Pattern.compile("([A-Z]{1}\\.[A-Z]{1}\\.[A-Z]{1}\\.){color:#ff6600}|{color}([A-Z]{1}\\.\\s[A-Z]{1}\\.\\s[A-Z]{1}\\.){color:#ff6600}|{color}([A-Z]{1}\\.[A-Z]{1}\\.){color:#ff6600}|{color}([A-Z]{1}\\.\\s[A-Z]{1}\\.){color:#ff6600}|{color}([A-Z]{1}\\.)");
    //In the above line I am trying to catch all the initials (3 initals, 2 initials & 1 initial)
    Matcher RegexMatcherTry1 = RegexTry1.matcher(chkEnty);
    while(RegexMatcherTry1.find())
    String chkEntyTry1 = RegexMatcherTry1.group();
    Tagged11="<fname>"+chkEntyTry1+"</fname>";
    fetchWholeFile=fetchWholeFile.replace(chkEntyTry1,Tagged11);
    After executing the above code, my out is
    *<name><fname>J.</fname>* E. O'Rrrrrr, *<fname>S.</fname>* Mmmmmmmmmm, *<fname><fname><fname><fname>B.</fname></fname></fname></fname> <fname>G.</fname>* Mmmmmmmm, *<fname>A.</fname>* *<fname><fname><fname><fname>B.</fname></fname></fname></fname>* *<fname>C.</fname>* Xxxxxx Yyyyy, *<fname>A.</fname>* *<fname><fname><fname><fname>B.</fname></fname></fname></fname>* *<fname>C.</fname>* Zzzz and *<fname>C.</fname>* *<fname><fname>R.</fname></fname>* McCcccc*</name>*
    But I need my out as below
    *<name><fname>J. E. </fname><sname>O'Rrrrrr</sname>,* *<fname>S. </fname><sname>Mmmmmmmmmm</sname>*, *<fname>B. G. </fname><sname>Mmmmmmmm</sname>*, *<fname>A. B. C. </fname><sname>Xxxxxx Yyyyy</sname>*, *<fname>A. B. C. </fname><sname>Zzzz </sname>and <fname>C. R. </fname><sname>McCcccc</sname></name>*
    Could some also tell me how do I apply *<sname>*

    prometheuzz my source code as suggested by you is
    public void lineread(String FileName)
         try
              File asciiFile1 = new File(FileName);
              File tmp = new File(asciiFile1.getParent(),"Temp.xml");
              BufferedReader br = new BufferedReader(new FileReader(asciiFile1));
              BufferedWriter bw = new BufferedWriter(new FileWriter(tmp));
              String line = "";
              while((line = br.readLine()) != null)
                   fetchWholeFile+=line;
              Pattern Regex = Pattern.compile("<ref.list>.*?</ref.list>");
              Matcher RegexMatcher = Regex.matcher(fetchWholeFile);
              while(RegexMatcher.find())
                   chkEnty = RegexMatcher.group();
              Regex = Pattern.compile("<name>.*?</name>");
              RegexMatcher = Regex.matcher(chkEnty);
              while(RegexMatcher.find())
                   chkEnty = RegexMatcher.group();
                   Matcher m1 = Pattern.compile("([A-Z]\\.\\s?)+").matcher(chkEnty);
                   while(m1.find())
                        String Fname1=(m1.group());
                        String Fname2=("<fname>"+m1.group()+"</fname>");
                        FnameVector1.addElement(Fname1);
                        FnameVector2.addElement(Fname2);
                   Matcher m2 = Pattern.compile("([A-Z]['a-z]+\\s?)+").matcher(chkEnty);
                   while(m2.find())
                        String Sname1=(m2.group());
                        String Sname2=("<sname>"+m2.group()+"</sname>");
                        SnameVector1.addElement(Sname1);
                        SnameVector2.addElement(Sname2);
              for(int v=0;v<FnameVector1.size();v++)
         System.out.println(FnameVector1.elementAt(v));//It's printing fine here      
              for(int v=0;v<FnameVector2.size();v++)
                   System.out.println(FnameVector2.elementAt(v));//It's printing fine here
                   fetchWholeFile=fetchWholeFile.replace(FnameVector1.elementAt(v).toString(), FnameVector2.elementAt(v).toString());//But if I update to input XML file, it's wrong as shown below
              for(int v=0;v<SnameVector1.size();v++)
         System.out.println(SnameVector1.elementAt(v));//It's printing fine here
              for(int v=0;v<SnameVector2.size();v++)
                   System.out.println(SnameVector2.elementAt(v));//It's printing fine here
                   fetchWholeFile=fetchWholeFile.replace(SnameVector1.elementAt(v).toString(), SnameVector2.elementAt(v).toString());//But if I update to input XML file, it's wrong as shown below
              bw.write(fetchWholeFile);
              bw.flush();
              bw.close();
              br.close();
              File org = new File(FileName);
              System.gc();
              System.out.println(asciiFile1.delete());
              tmp.renameTo(org);
         catch(IOException ioe)
              System.out.println(ioe);
    This is my XML file
    <?xml version="1.0" encoding="UTF-8"?>
    <ref-list>
    <name>A. B. Cccccc and X. Y. Zzzzzz</name>
    <name>K. Name</name>
    The output after executing the above source code is
    <?xml version="1.0" encoding="UTF-8"?>
    <ref-list>
    <name><fname>A. </fname>B. <sname>Cccccc</sname>and <fname>X. <fname>Y. </fname></fname><sname>Zzzzzz</sname></name>
    <name><fname><fname><fname><fname><fname><fname>K. </fname></fname></fname></fname></fname></fname><sname>Name</sname></name>
    But I need my output as
    <?xml version="1.0" encoding="UTF-8"?>
    <ref-list>
    <name><fname>A. B. </fname><sname>Cccccc</sname>and <fname>X. Y. </fname><sname>Zzzzzz</sname></name>
    <name><fname>K. </fname><sname>Name</sname></name>
    Please tell me where have I gone wrong.

Maybe you are looking for

  • Changing default name of FDF file created by submit button

    Hi all, I was wondering if there was a way to change the default file name used by acrobat when the submit button is clicked. Currently, when a user clicks the submit button on my form, acrobat allows them to generate an FDF file and either save it t

  • IMac 27inch built in SD slot not detecting

    Recently, I wanted to use my SD slot to upload pictures from my camera. It has been working fine before and now all of sudden it doesn't read the card at all once I put in the built in slot on the side. At first I thought it was the SD card but when

  • Screen Reader Tech responsiveness in Adobe Pro vs. Adobe Reader

    I created a custom form using LiveCycle ES2. I am testing the usability of the form in conjunction with Screen Reader Technology (specifically NVDA) in Adobe Professional 9 and Adobe Reader X. The text fields that are read aloud by the Screen Reader

  • Have over 20,000 photos, any way to easily find and delete duplicates?

    So I got more than 20,000 photos and I know many of them are duplicates. Used to have the Kodak picture program that when you had all the pictures listed it would show duplicates next to each other so that it was very easy to delete them. Does Elemen

  • New login in oracle forums

    i have a doubt not linked to this forum that how to create a new login to access the forums. I went to http://forums.oracle.com/forums/ but there does not look any provision to create a new login, it only shows access for existing users to login. I h