Question: I'm working on a simple lightbox script for my website, that wraps a link (A) around a image. The link URL should then be the SRC of the image, but slightly manipulated.

The image URL could look like this: "pb028855\_copy\_147x110.jpg" and I want it to delete "*147x110", from after "copy*" to before ".jpg" that is.

My current script, to copy the SRC from the image to the link is like this:

```
$(function(){
    $('img.withCaption').each(function(){
        var $imgSrc = $(this).attr("src");
        $(this).wrap('<a rel="lightBox" />');
        $(this).parent().attr("href", ""+$imgSrc);
    });
});

```

How can I use parts of a attr?

Thank you in advance...

Answer: 
If you're not certain exactly what the numbers will be, you could use the [`replace()`*(docs)*](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String/replace) method with a regular expression.

```
$(function(){
    $('img.withCaption').each(function(){
        var $imgSrc = this.src.replace(/_\d+x\d+\./,'.');
        $(this).wrap('<a rel="lightBox" />')
               .parent().attr("href", ""+$imgSrc);
    });
});

```

So this:

```
pb028855_copy_147x110.jpg

```

will end up as this:

```
pb028855_copy.jpg

```
They are several ways of manipulating strings, depends of what you exactly want, for example:

```
$imgSrc = $imgSrc.replace(/thumb/, 'big');

```