Athapali
Athapali

Reputation: 1089

Regular expression string compare ignoring symbols

I have two variables:

varAdditionalTeamAddress = ;; [email protected]

VariableAddTeamEmails =  ; [email protected];

These two variables are being used to concatenate and collect additional support team emails. But in the process of concatenation, if the emails are empty, only the semicolons come over.

I need to compare these two variables (ignoring the ;) to see if they are equal. Can we write a regular expression to extract all semicolons and spaces from this email string so they are comparable?

Like for the above, had I cleaned them up by excluding the spaces and semicolons, the equality test would have returned TRUE.

Regex gurus, please help. PS I need REGEX way of doing this.

Upvotes: 1

Views: 51

Answers (3)

obfuscate
obfuscate

Reputation: 140

If you are on windows using PowerShell then you can do this

$varAdditionalTeamAddress = ";; [email protected]"
$VariableAddTeamEmails = " ; [email protected];"

if ( ($varAdditionalTeamAddress.Trim() -replace '(;+|\s)','') -eq ($VariableAddTeamEmails.Trim() -replace '(;+|\s)','')){
    Write "Email Strings are equal"
}else{
    Write "They Seem to different"
}

Upvotes: 0

karkael
karkael

Reputation: 473

sorry for compressed code :

if( 
     VariableAddTeamEmails.match( /\w+@\w+\.\w+/g ).indexOf( 
          varAdditionalTeamAddress.match( /\w+@\w+\.\w+/g )[ 0 ] )  
     ) != -1
){
 // ...
}

My regexp isn't exactly the best way to get address mail. There are many subjects on it on StackOverFlow.

Upvotes: 0

anubhava
anubhava

Reputation: 785246

You can do:

varAdditionalTeamAddress = varAdditionalTeamAddress.replace(/^[ ;]+/, "");

VariableAddTeamEmails = VariableAddTeamEmails.replace(/^[ ;]+/, "");

to remove any combination of ; and space from start of your variables.

Upvotes: 2

Related Questions