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 whitespacehref=
-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
Post a Comment