Get the App
SLTechnology News&Howtos  ›  Development  › 

Is comp the JavaScript method?

Shulou Source: shulou.com Published: 2022-06-03 18:43:49 09月17日 Update

This article mainly introduces whether comp is a JavaScript method, which has certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article. Let Xiaobian take you to understand it together.

Comp is not a JavaScript method, compile is a JavaScript method; the compile method is used to compile regular expressions during script execution and can also be used to change and recompile regular expressions.

Operating environment: Windows 7 system, javascript version 1.8.5, DELL G3 computer.

Is comp a JavaScript method?

comp is not a JavaScript method, and compile() is a JavaScript method.

JavaScript compile() method

The compile() method is used to compile regular expressions during script execution.

The compile() method can also be used to change and recompile regular expressions.

syntax

RegExpObject.compile(regexp,modifier)

Parameter regexp regular expression.

modifier Specifies the type of match. "g" for global matching,"i" for case-sensitive, and "gi" for global case-sensitive matching.

Note: All browsers except Opera support compile().

examples

Search globally for "man" in the string and replace it with "person." Then change the regular expression by using the compile() method, replacing "man" or "woman" with "person":

var str="Every man in the world! Every woman on earth! ";var patt=/man/g;var str2=str.replace(patt,"person");[xss_clean](str2+"

");patt=/(wo)? man/g;patt.compile(patt);str2=str.replace(patt,"person");[xss_clean](str2);

The output of the above example:

Every person in the world! Every woperson on earth! Every person in the world! Every person on earth! Thank you for reading this article carefully. I hope that the article "comp is not a JavaScript method" shared by Xiaobian will help everyone. At the same time, I hope that everyone will support it a lot and pay attention to the industry information channel. More relevant knowledge is waiting for you to learn!

Tags: Method regular expression article compilation global size instance browser script procedure support browsing value interest parameter at the same time character string more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Shulou Tech Info Shulou Information Microsoft NVidia