Regular expression for certain amount of characters
-
12-11-2019 - |
Question
I'm trying to change a lot of URLs with TextWrangler, those ending with m.htm
should lose the m
, but only if the total number of characters in the filename is 7. Those with fewer characters should not be changed.
I've tried
/.*?{7}m.htm/
but it doesn't work...
What is the solution?
Solution
Replace
href="([^"]*)\/(.{6})m.htm([^"]*)"
Meaning : href="
followed by any non "
character until a /
(the latest the better: greedy) then 6 character followed by a m
, then any non "
character.
By
href="\1\/\2.htm\3"
Meaning :
\1 = [^"]*
\2 = .{6}
\3 = [^"]*
Example
<a href="google.com/foo/bar/urzadjm.htm">testM</a>
\1 : google.com/foo/bar
\2 : urzadj
\3 : <empty>
If files can be htm
and php
, I suggest to replace .htm
by (.htm|.php)
(!Warning to back-references change in numbers!)
OTHER TIPS
May be
/\b.{6}m\.htm/
That is, starting on the word boundary, followed by any 6 symbols, followed by m.htm.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow