I want to extract "abc" from "images/abc.png" using Javascript Regular experssion in one line.
i have tried this
<script type="text/javascript">
var str = "images/abc.png";
var patt1 = /images\/[a-z]+?/i;
document.write(str.split(patt1));
</script>
You want to use a capture group, e.g.:
You can do it on one line only if you know that it will match; otherwise you’ll get an exception.
Actually, I could cheat and use the comma operator to get it on one line:
…but I think it looses a lot of clarity.
The MDC page on regular expressions is useful reading.