Reputation: 3068
I want to build an expression which returns all the phrases which start with a given string and not ends with a given string and contain a special character Example:
Starts with href="
doesn't contain .
and not ends with /
Matches
href="blah/foo"
href="foo"
Doesn't match
href="blah/foo.css"
href="blah/foo.ico"
href="blah/foo."
href="blah/"
href="blah/foo.css/"
I tried to build something like this (href=\")^((?!.).)|(?!.*\/$)*$
but I'm stuck at the moment.
I also want to be able to add a phrase to the end of each occurrence.
Upvotes: 1
Views: 507
Reputation: 626748
You may use
Find: (href=")([^".]*[^"./])(")
Replace: $1$2.html$3
See the regex demo
Details
(href=")
- Group 1 ($1
): href="
substring([^".]*[^"./])
- Group 2 ($2
): any 0+ chars other than "
and .
followed with any char but "
, .
and /
(")
- Group 3 ($3
): a "
char.Test in VS Code:
Upvotes: 1
Reputation: 37755
You can try this mate
href="[^.\s]+?(?!\.)[^\/.]"$
Explanantion
href="
- Will match exactly href="
.[^.\s]+?
- Will match anything except .
and space one or more time (lazy mode).(?!\.)
- Negative look ahead. It checks for .
.[^\/.]$
- Checks for end of string should not contain /
or .
Upvotes: 0