I am using handlebars. So I need a way to detect all {{#link-to 'route-name'}}...
helpers that dont start with home name. I am new to regex so I cannot find good regex. Bad example: ([^home]|^) {{#link-to
You're using the [^...]
term, which means any character except those in the brackets, so [^home]
should match any character except for h
, o
, m
and e
.
In your case, what you're searching for is a Negative Lookahead:
^.+\s?{{#link-to '(?:(?!home).{0,4}.*)'}}
Take a look at this Regex101 working example .
^
Matches start of a text (or line, with /m flag enabled) .+
Matches the name of the element (You may remove it if needed) \\s?
Matches one or zero occurrences of a whitespace character ( \\s
, you also may remove) {{#link-to '
The literal form of the text to be matched (?:
Start of a non-capturing group (?!
Start of a negative lookahead group home
Literal text to NOT be matched )
End of the negative lookahead group .{0,4}
Matches any zero-four characters except if they value is home
(because of the (?!home)
) .*
If the link-to's name is longer than four characters, match them. )
End of the non-capturing group '}}
Literal text to match (end of the route link)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.