CoffeeScript Regular Expressions - CoffeeScript

What is CoffeeScript Regular Expressions?

A regular expression is an object that defines a pattern of characters JavaScript ropes. In JavaScript, RegExp class signifies regular expressions, and both String and RegExp define methods that use regular expressions to perform powerful pattern-matching and search-and-replace functions on text.

What is Regular Expressions in CoffeeScript?

The regular expressions in CoffeeScript are same as JavaScript.

Syntax

A regular expression in CoffeeScript is defined by placing the RegExp pattern between the forward slashes as shown below.


Example
Resulting is an example of regular expressions in CoffeeScript. In here, we have created an expression that finds out the data that is in bold (data between <b> and </b> tags). Save this code in a file with name regex_example.coffee

Open the command prompt and compile the .coffee file as shown below.

On compiling, it gives you the following JavaScript.

Now, open the command prompt again and run the CoffeeScript file as shown below.

On executing, the CoffeeScript file produces the following output.

Heregex

The complex regular expressions we write using the syntax supplied by JavaScript are unreadable, therefore to make regular expressions extra readable; CoffeeScript gives a prolonged syntax for normal expressions known as heregex. The usage of this syntax, we can break the everyday normal expressions using whitespaces and we also can use feedback in these prolonged ordinary expressions, hence making them more user-friendly.

Example

the subsequent example demonstrates the use of the advanced regular expressions in CoffeeScript heregex. In here, we are rewriting the above instance the use of the advanced ordinary expressions. store this code in a report with call heregex_example.coffee

Open the command prompt and compile the .coffee file as shown below.

On compiling, it gives you the following JavaScript.

Now, open the command prompt again and run the CoffeeScript file as shown below.

On executing, the CoffeeScript file produces the following output.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

CoffeeScript Topics