Javatpoint Logo
Javatpoint Logo

Javascript regexp Lookbehind

Lookbehind patterns enable JavaScript to move backward using the string to search for specified patterns. Lookaround is a combination of the Lookahead and Lookbehind expression. If input values come after another group of characters, we use the specific group of characters using lookbehind. When we wish to find various patterns within the same string, this is useful.

Syntax

The following syntax shows the positive Javascript regexp Lookbehind

The following syntax shows the negative Javascript regexp Lookbehind

Explanation

There are two different kinds of lookbehind, which are as follows:

  • Positive lookbehind: It is going to determine whether a specific element is included in the pattern but won't actually match it.
  • Negative lookbehind: It uses to check if a specific element is absent after the search pattern. Enclosing a specific pattern between patterns (?!) shows in a negative lookbehind.

Examples

The following examples show the positive and negative lookbehind of the regular expression.

Example1:

In the example, the "butter" matches with the fly or milk using the positive lookbehind expression. The first value comes after the pattern value then the output shows the true value.

Output

The following image shows the Boolean values as an output.

Javascript regexp Lookbehind

Example2:

In the example, the "butter" matches with the fly or milk using the positive lookbehind expression. We can test the regular expression using the lookbehind pattern expression.

Output

The following image shows the data values as an output.

Javascript regexp Lookbehind

Example3:

In the example, the "butter" matches with the fly or milk using the negative lookbehind expression. If the first value does not get after the last value, then the output shows the true value. If the first value does not match with the last value, then the output shows a false value.

Output

The following image shows the Boolean values as an output.

Javascript regexp Lookbehind

Example4:

In the example, the "butter" matches with the fly or milk using the positive lookbehind expression.

Output

The following image shows the Boolean values as an output.

Javascript regexp Lookbehind

Example5:

In the example, the lookbehind regexp uses to get the available values from pattern values. We can use the console tab, alert, and other output tabs to show after values. We can use the javascript match function with the expression function. Here, the output shows the values that come after the input value.

Output

The following image shows the available values as an output.

Javascript regexp Lookbehind

Example 6:

In the example, the negative lookbehind regexp uses to get the available values from pattern values.

Output

The following image shows the exact values as an output.

Javascript regexp Lookbehind

Supported Browsers:

The following browsers support the javascript lookbehind expression.

  • Google Chrome
  • Firefox
  • Internet Explorer
  • Opera
  • Safari

Conclusion

The javascript lookbehind expression searches the required keyword in the string value after the input value. This expression uses for pattern recognization and operation.







Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA