Skip to content

Instantly share code, notes, and snippets.

@simondell
Created November 5, 2012 11:03
Show Gist options
  • Save simondell/4016649 to your computer and use it in GitHub Desktop.
Save simondell/4016649 to your computer and use it in GitHub Desktop.
Find HTML buttons regex

Match buttons

A regular expression for finding HTML buttons, which captures the value attribute, content and any other attributes. You could use this in a replace function to change the type of the control to an input, whilst keeping most of its metadata and options.

[ a-zA-Z0-9_\-="]+ means "match any letter, number, space, hyphen, quote or underscore, one or more times". It roughly matches the allowed characters for HTML attributes and their values. If your attributes were more complex, including '&' or entities for example, you'd need to expand on this regex.

<button([ a-zA-Z0-9_\-="]+)value="([ a-zA-Z0-9_\-]+)">(.*?)</button>
@Boburiy1906
Copy link

asdfbgh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment