Ritesh Jagga
Ritesh Jagga

Reputation: 1442

Webstorm MAC OSX: Regular expression for backreference is not working in replace field

In WebStorm, I am using Find and Replace functionality with regular expression to replace hexadecimal color code to an upper case equivalent e.g. #ddd to #DDDDDD.

Image to show what I tried: enter image description here Find field have #[0-9a-z]{3,6}; regular expression and it finds color codes correctly. Replace field have \U$1\.

Regular expression is not recognized in the replace field. The tooltip says Empty string. I tried with other values too.

I refered PhpStorm's documentation on Changing case of the characters and I believe it should be valid for WebStorm too.

Upvotes: 1

Views: 339

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 627128

It is important to note that Webstorm uses Java regular expressions:

WebStorm is the Java-based application, so we use Java engine to process everything, including Regular Expressions.

Java regex does not support \U nor \u, \l or \L operators.

However, you can use them in Notepad++.

I see you followed the Webstorm Help page that shows an example search and replace with \stitle="(.*)?"\s*(/>*) regex and \U$1 replacement.

The $1 is a backreference to what has been captured by the first subpattern inside round brackets. Since #[0-9a-z]{3,6}; has no pairs of unescaped parentheses, $1 backreference does not point to any text. Instead, use Group 0: \U$0.

If you want you can define the first capturing group round the whole pattern: (#[0-9a-z]{3,6};) and then use your replacement pattern.

Upvotes: 1

Related Questions