Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternative to lookbehind with variable width

I have some html which contains a number of hyperlinks to html files, but they don't have any file extensions.

For example in the string <a href='variablelengthfilename'> I'm trying to match the trailing ' , so I can replace it with .html' (using a RegEx search in Notepad++) using something like this:

`(?<=href='[A-Za-z]*)'` 

but that won't work because Notepad++ doesn't allow variable-length lookbehind assertions.

How else can I achieve this?

Thanks

like image 671
Dave Avatar asked Mar 21 '26 08:03

Dave


1 Answers

Since you are working in Notepad++, here is a way to achieve what you are after:

Find what: \bhref='[^']*

Replace with: $&.html

The \bhref='[^']* regex matches a href as a whole word, then =' are matched literally, and [^']* matches 0 or more characters other than '. Note you will need to replace ' with " if the href value is inside double quotes.

enter image description here

like image 92
Wiktor Stribiżew Avatar answered Mar 23 '26 22:03

Wiktor Stribiżew



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!