search and replace using regular expressions in java
<p>I need to find and replace all dates present inside a document(basically bring it to present date). The problem in using regex is if the date is in this format</p>

<pre><code>CreationDatetime="2012/07/24 10:00:19 649 GMT"
</code></pre>

<p>the regex will not find this entry as the date is attached to another string. Is there any other way to find dates in all formats (    yyyymmdd, yyyy/mm/dd etc.) and bring it to the current date.</p>

<p>working code for search for one format (yyyymmdd) but the replace doesn't work now.</p>

<pre><code>String re1=".*?";   // Non-greedy match on filler
String re2="((?:(?:[1]{1}\\d{1}\\d{1}\\d{1})|(?:[2]{1}\\d{3}))[-:\\/.](?:[0]?[1-9]|[1][012])[-:\\/.](?:(?:[0-2]?\\d{1})|(?:[3][01]{1})))(?![\\d])"; // YYYYMMDD 1

    Pattern p = Pattern.compile(re1+re2,Pattern.CASE_INSENSITIVE | Pattern.DOTALL);



    for(Object s : x){
        String temp = s.toString();
        Matcher m = p.matcher(s.toString());
        if (m.find())
        {
            temp.replaceAll(re1+re2, "test");
            System.out.println(temp.toString());
        }
</code></pre>
