• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How handle match () for brackets

New Here ,
Nov 27, 2018 Nov 27, 2018

Copy link to clipboard

Copied

Hi,

I have a small script to compare two text messages. Even though both text messages are same, the scripts outputs an alert message saying "Text Do Not Match".

Please let me know, how can I handle this situation.

1. var text1 = "USE PROTECTIVE EQUIPMENT (GOGGLES FACE SHIELD) WHEN USING COMPRESSED AIR."

2. var text2 = "USE PROTECTIVE EQUIPMENT (GOGGLES FACE SHIELD) WHEN USING COMPRESSED AIR."

3. if (text1.match (text2))

4. alert ("Text matches");

5. else

6. alert ("Text Do Not Match");

TOPICS
Scripting

Views

201

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Nov 27, 2018 Nov 27, 2018

If you want to keep both as strings, use this in your comparison:

if (text1 === text2)

Votes

Translate

Translate
Community Expert ,
Nov 27, 2018 Nov 27, 2018

Copy link to clipboard

Copied

The match method on a string requires a regular expression as a parameter. text2 would have to be like this in order to match:

var text2 = /USE PROTECTIVE EQUIPMENT \(GOGGLES FACE SHIELD\) WHEN USING COMPRESSED AIR\./;

-Rick

www.frameexpert.com

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 27, 2018 Nov 27, 2018

Copy link to clipboard

Copied

LATEST

If you want to keep both as strings, use this in your comparison:

if (text1 === text2)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines