regex - Regular Expression to match between quotes only if also contains / -


i trying clean bunch of anchor tags. relative paths used bunch of sub directories , have moved files single directory, need clean links removing references sub directories them. there thousands of files modify , trying write reliable regular expression clean them up.

below example of types of lines coming across , having trouble writing work types.

starting:

<a href="choosefile.html">choosing file type</a> <a href="deletefiles.html">deleting file</a><br /><a href="exporting_a_file/exportwindow.html">  <a href="importing_a_file/importwindow.html"> <a href="searching/searching_for_a_file/searchpanel.html"> 

goal:

<a href="choosefile.html">choosing file type</a> <a href="deletefiles.html">deleting file</a><br /><a href="exportwindow.html">  <a href="importwindow.html"> <a href="searchpanel.html"> 

currently have below expression, when there more 1 anchor tag on same line doesn't work.

(?<=href\=([\"'])).*(?<=[a-z])(?:\\|\/)(?=[a-z]) 

if data consistent, may use

\shref=(["'])\k(?:(?!\1).)*/ 

see regex demo (note / might need escaping, depends on using regex).

  • \s - matches whitespace
  • href= - href= substring
  • (["']) - ' or " quote (group 1)
  • \k - omit text matched far
  • (?:(?!\1).)* - 0 or more chars other ' or " (the value depends on captured group 1)
  • / - / char.

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -