Click here to Skip to main content
15,890,527 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi,

First, there is a string called:
JavaScript
var bookPath = '../MyBook/Computer/Sample_1/Sample_1_p16.pdf';

And here is my regular expression:
JavaScript
bookPath = bookPath.replace( /Sample.+pdf/gi, "" );

Finally, the result of bookPath is "../MyBook/Computer/".
How do I get "../MyBook/Computer/Sample_1/" instead?

Many thanks~
Posted

 
Share this answer
 
Use this for an example:

XML
<html>
<head><title>Regular Expression Test</title>
<script type="text/javascript">
function Test (value) {
    alert(value.replace(/\w{2}\d{1,2}\.pdf/i, ""));
}
</script>
</head><body>
<form action="">
<input type="button" value="Test 1" onclick="Test('../MyBook/Computer/Sample_1/Sample_1_p16.pdf')">
</form>
</body></html>


Best Regards,

—MRB
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900