Jooman-g
Jooman-g

Reputation: 3

Google Apps Script not recognizing strings with parentheses and brackets as part of the string

I have a conditional that is supposed to compare two strings:

if (parametros.toString().toLowerCase().match(valor_celda_activa.toString().toLowerCase()) != null){
...actions here...
}

This works ok UNTIL there is some parentheses or bracket inside the string.

Working example strings:
parametros = "1.01 - Sourcing Gathering information"
valor_celda_activa = "1.01 - Sourcing Gathering information"

NOT working example strings:
parametros = "1.01 - [Sourcing] Gathering information"
valor_celda_activa = "1.01 - [Sourcing] Gathering information"

Note the brackets inside the strings. As long as the brackets are present, the code won't work. This also happens with parentheses.

Haven't actually found this kind of specific situation from someone else on the internet.

This is really my first question on StackOverFlow so feel free to feedback or request more information that I might have missed.

Upvotes: 0

Views: 579

Answers (1)

TheMaster
TheMaster

Reputation: 50764

String.match expects a regular expression. Square brackets [] have special meaning in . For plain text matching, just use ===:

if (parametros.toString().toLowerCase() === valor_celda_activa.toString().toLowerCase()){

Upvotes: 1

Related Questions