如何在Javascript中使用正则表达式匹配定义的模式(How to match defined pattern using regular expression in Javascript)

   IT问题网   2021-02-22 00:00:00

问 题

嗨,



首先,有一个字符串叫做:

  var  bookpath = '  ../ mybook / computer / sample_1 / sample_1_p16.pdf'; 


这是我的正则表达式:

 bookpath = bookpath.replace(/sample.+pdf/gi, " "); 


最后,结果bookpath的内容是"../mybook/computer/"。

如何获得"../mybook/computer/sample_1/"?



非常感谢

解决方案

嗨,



如果有帮助的话,请看这个链接。

使用javascript获取url参数

解析查询字符串的简便方法您获取某些值的网址。





问候,



algem

以此为例:



 lt;   html  gt;  
lt; head gt; lt; title gt; 正则表达式测试lt; / title gt;
lt; script 类型 =" text / javascript" gt;
函数测试(值){
alert(value.replace(/ \w {2} \d {1,2} \。 pdf / i,""));
}
lt; / script gt;
lt; / head gt; lt; body gt;
lt; 表格 action =" " gt;
lt; input type =" 按钮" value =" 测试1" onclick =" 测试('../ mybook / computer / sample_1 / sample_1_p16.pdf')" gt;
lt; /表格 gt;
lt; / body gt; lt; / html gt;




最好的问候,


-mrb

标签:何在使用正则表达式匹配定义模式



分享:

  • 微信
  • QQ好友
  • QQ空间
  • 新浪微博


热门推荐

我想打印收据,但我遇到了问题(I want to print a reciept but i face a problem)

problem in this project i am using datareport ...

Visual Studio 2010 + Windows 7 + 64位计算机+ C ++ + 32位DLLS = 3个问题(Visual Studio 2010 + Windows 7 + 64-bit computer + C++ + 32 bit DLLS = 3 problems)

problem i''ve been using visual studio 2005 for many year ...

什么是Eclipse以及如何使用它?(What is about Eclipse and how to use it)

problem how to use it .and for what purpose it is used so ...

如何从数据库中检索数据?(how to retrieve data from database)

problem i have a radiobuttonlist control and i want to re ...

使用SQL Management Studio将数据插入我的数据库时执行NonQuery(ExecuteNonQuery while inserting the data into my database using SQL Management Studio)

problem hi i have a problem while inserting the data int ...

我如何将C#.Net中的拖放图像转换为ASP.Net(how do i convert Drag and drop image in C#.Net to ASP.Net)

problem hi, i saw the drag and drop image in c#.net arti ...

如何禁用浏览器的后退按钮(How to disable browser's back button)

problem hello friend, i am using asp.net framework 3.5,i ...

滚动后无法打印文本....(Unable to print text after scrolling....)

problem hi, i have written a small c program ...

我使用radgrid,我从数据库获取列名,但我希望他们的名称作为不同的名称,如何重命名RadGrid的列名(Im using a radgrid ,i get column names from database but i want their names as diferent names,How to rename those columns names of RadGrid)

problem im using a radgrid ,i get column names from datab ...

用于showbits函数的头文件(header file to be used for showbits function)

problem which header file shd be used for showbits() func ...

在gridview控件中删除事件行。(Row Deleting event in gridview control.)

problem i am trying to delete userid and groupid from the ...

如何查看.dll文件中编写的代码?(how to view code written in .dll file)

problem hi to all.i have downloaded source co ...

登录 - 使用哈希值检查密码(login - check password with hashed one)

problem this is my code to hash class hashin ...

上传图片时出现问题(problem in uploading images)

problem i want to upload images that will be saved in a f ...

如何使用c#向Bixolon热敏打印机发送命令(How to Send commands to Bixolon thermal printer using c#)

problem first of all , i have searched on goo ...

图像波动问题(image fluctuation problem)

problem i want to know how to remove image fluctuate from ...

LISTVIEW每行的随机ID(LISTVIEW random id for each row)

problem hi, all i want is to generate an id ...

如何创建自定义Web控件......?(How to create a custome web control...)

problem 1) i want to create a class that will inherited f ...

如何管理该代码(how to manage that code)

problem my question is......... we have 3 buttns on page ...

如何删除sysobjects中的列数据但不删除它们的关系(how to delete columns data in sysobjects but not deleted their relations)

problem hello how to delete all system table columns dat ...