Regxr: Select pattern

Viewed 60

I'm new to a regular expression. How can I select a pattern like data-v-**=""from a string?

Here is my code is to match that pattern: data-v-.+"$, but it's not working. Can anyone help me to fix it?

Example String:

<div data-v-41dfcbba="" class="aaaaaa" style="width: 100%; height: 100%;"><div data-v-fc1d9bbe="" data-v-41dfcbba="" style="height: 100%;"><div data-v-0392e45a="" data-v-fc1d9bbe="" class="example-class">

Expected result:

data-v-41dfcbba=""
data-v-fc1d9bbe=""
data-v-41dfcbba=""
data-v-0392e45a=""
data-v-fc1d9bbe=""
2 Answers

You can use

data-v-[^\s"]+="[^"]*"
  • data-v- Match literally
  • [^\s"]+ Match 1+ times any char except a whitespace char or "
  • ="[^"]*" Match an equals sign, and from an opening till closing double quote

Regex demo

With your shown samples, please try following.

data-v-[^=]*="[^"]*"

Online demo for above regex

Explanation:

  • data-v-: Matching from data-v-: here.
  • [^=]*=: Matching everything till 1st occurrence of = then match 1st occurrence of =: here.
  • "[^"]*": Matching ", then matching everything till 1st occurrence of ", then matching ": here.
Related