How would a regular expression find an attribute html + attribute value?

Asked

Viewed 187 times

2

I want to give a find/replace in all the attributes html "data-placeholder" and its values, of my application, through the search of Visual Studio.

For this I need to assemble a regular expression and place it directly in the Visual Studio find, activating the regular expression option.

But I know almost nothing about regular expressions to be able to create one like.

I would like the regular expression to make me find all these string types:

data-placeholder="Texto 1"
data-placeholder="Texto 2"
data-placeholder="Texto com muitos caracteres"
data-placeholder=""

2 answers

4


I’m not very wild in regex rs, but I’ll try to help:

(data-placeholder=")(\w+(\s+|\w+)\w+)"
  • Perfect! I will save to use in other situations!

1

You can make it so :

data-placeholder="([a-zA-Z0-9 ]*)"

Case _ no problem if it diminishes it to :

data-placeholder="([\w ]*)"

Explanation

  1. data-placeholder=" literal search, must contain in string.
  2. (...) Generates a group, match[1], because match[0] is the own string.
  3. [a-zA-Z0-9 ] or [\w ] sequence of valid characters, no matter the order.
  4. * quantified, from zero to infinity, always capturing the maximum.
  5. " literal search, must contain in string.

Obs

\w = [a-zA-Z0-9_]

Browser other questions tagged

You are not signed in. Login or sign up in order to post.