Editing template variables using regularExpression()

I'm building a template for web components whose class names should depend on the file name. In practice:

prefix-component-name.tsx

should return

ComponentName

Now, I was able to return the desired component name including the prefix with the following expression:

capitalize(camelCase(fileNameWithoutExtension()))

I though in order to strip the prefix I could use a regular expression:

regularExpression(camelCase(fileNameWithoutExtension()), ^.+[-], "")

However, it obviously didn't work. I couldn't find any example about regularExpression(String, Pattern, Replacement) usage in the docs. Any help please?

0
7 comments

Thank you @Elena!

I had to wrap the pattern in quotes to make it work: 

capitalize(camelCase(regularExpression(fileNameWithoutExtension(), "^[^-]*-", "")))

 

1

I tried many ways and cannot get this to work.

Currently running IntelliJ 2020.3.2 Ultimate.

Examples (that do NOT work):

regularExpression("foobar", "r", "n")
regularExpression("foobar", /r/, "n")
regularExpression("foobar", r, "n")
0
regularExpression("foobar", "r", "n")

works fine for me

0

I'm not sure what happened. After a restart it seems to work.

Maybe something crashed internally. I tried to get this working for about an hour and tried every possible way it could think of.

The position where this regex should show up, always ended up being empty.

0

Can I use capture group?  How will I do?

0

regularExpression(String, Pattern, Replacement) Live Template function is implemented as Java String.replaceAll(Pattern, Replacement). Please refer to java Pattern documentation for information on the supported syntax

0

Please sign in to leave a comment.