Reputation: 68750
I need to find a word this
within <template>
and </template>
:
I tried <template>([this])*?<\/template>
but it doesn't seem to work.
https://regex101.com/r/VmGESa/1
Upvotes: 0
Views: 73
Reputation: 2956
Your regular expression is matching strings that
<template>
,t
, h
, i
or s
with arbitrary length, e.g., thssiththissiththhtht
would be matched by ([this])*
,</template>
,Does this solution work for you?
<template>(?:.|\n|\r)*(this)(?:.|\n|\r)*<\/template>
.*
matches an arbitrary number of arbitrary characters, except for new lines. So, I added \n
and \r
with the OR operator |
. (?:...)
means, it's a non-capturing group, i.e., when asking for groups, this group won't show up.
Upvotes: 1
Reputation: 43728
You do not need the multiline m
flag and .
doesn't match linebreaks so you have to account for that.
E.g.
<template>(?:.|\r|\n)*?(this)(?:.|\r|\n)*?<\/template>
https://regex101.com/r/krkP9d/1
Upvotes: 1