1

我得到了这段代码。

    imgsrc = imgsrc.replace('-UNKNOWN_NUMBERx50.jpg','.jpg');

那么如何更改它以使其正确替换该值,无论它是“80x50.jpg”还是“120x50.jpg”或其他任何东西?

提前致谢 ;)

4

1 回答 1

0

For a regex replace, you need to use the forward slash delimiters like this and escape meta characters if there are any, and in this case, you have the dot .:

imgsrc = imgsrc.replace(/-\d+x50\.jpg/,'.jpg');
                        ^            ^

See if that works now.

\d+ means 1 or more digits. If you want to have a digit without a leading 0, use something like this instead of \d+: [1-9]\d*

于 2013-09-29T10:28:32.093 回答