Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KrashLeviathan/cb8a81cb3ae9bb0e49e9c01b81456def to your computer and use it in GitHub Desktop.
Save KrashLeviathan/cb8a81cb3ae9bb0e49e9c01b81456def to your computer and use it in GitHub Desktop.
Regex use case: Locating an HTML element that does NOT contain a given attribute

Negative Lookahead with Wildcard

This regular expression looks for <input> elements in HTML that do not contain the string "fieldSize". Presumably, you might want to look where all such elements are located in a code base so that you can add that attribute to each of them. This could be extended to other use cases as well.

<input(?![\s\S]+fieldSize)[^>]+>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment