Skip to content
Advertisement

Use variables in pattern matcher

I have the following:

JavaScript

But would like to replace the {6,20} with variable values due to them been dynamic in some cases.

I.e.

JavaScript

How can I include variables in the Reg Exp?

Thanks

Advertisement

Answer

Use Java’s simple string concatenation, using the plus sign.

JavaScript

Indeed, as Michael suggested compiling it is better for performance if you use it a lot.

JavaScript

Then use it when needed like this:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement