0

I get computed background style of an element and the result is like this:

rgba(0, 0, 0, 0) linear-gradient(45deg, rgba(126, 47, 182, 0) 0%, rgba(126, 47, 182, 0) 25%, rgba(249, 71, 157, 0) 80%, rgba(249, 71, 157, 0) 100%) repeat scroll 0% 0% / auto padding-box border-box

What regular expression can I use to match only linear-gradient(45deg, rgba(126, 47, 182, 0) 0%, rgba(126, 47, 182, 0) 25%, rgba(249, 71, 157, 0) 80%, rgba(249, 71, 157, 0) 100%)

  • the goal is to extract the part that I selected in bold -> linear-gradient(45deg, rgba(126, 47, 182, 0) 0%, rgba(126, 47, 182, 0) 25%, rgba(249, 71, 157, 0) 80%, rgba(249, 71, 157, 0) 100%) – Alexander Cherednichenko May 30 '17 at 15:00
  • Looks like famfamfam got the answer here: [swift split css linear-gradient using regex](https://stackoverflow.com/q/70677799/3345375) – jkdev Feb 15 '22 at 04:52
  • Also related: [parse css gradient rule with Javascript regex](https://stackoverflow.com/q/20215440/3345375) – jkdev Feb 15 '22 at 04:53
  • And: [How does one extract the color-stop values from a string which contains the definition of a linear gradient?](https://stackoverflow.com/questions/67065689/how-does-one-extract-the-color-stop-values-from-a-string-which-contains-the-defi) – jkdev Feb 15 '22 at 04:56

1 Answers1

3

Try the :

linear-gradient\([^(]*(\([^)]*\)[^(]*)*[^)]*\)

visual

See demo in https://regex101.com/

Paul Vargas
  • 41,222
  • 15
  • 102
  • 148