Skip to content

Commit

Permalink
fix(utils): improve email regex to avoid partial matches
Browse files Browse the repository at this point in the history
- Updated `emailRegex` in `src/utils/text-transform.ts` to include word boundary markers (`\b`) at both ends.
- This change ensures more accurate email matching and prevents partial matches in strings.
  • Loading branch information
cswni committed Feb 4, 2025
1 parent 77406f2 commit df33aff
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/utils/text-transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ const specialChars = [
* - The "g" flag enables global matching, allowing multiple occurrences
* of email addresses to be matched in a single string.
*/
const emailRegex = /[a-zA-Z0-9][a-zA-Z0-9._%+-]*@(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}/g;
const emailRegex = /\b[a-zA-Z0-9][a-zA-Z0-9._%+-]*@(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}\b/g;


/**
* Removes special characters from the given text string and returns the cleaned string.
*
Expand Down

0 comments on commit df33aff

Please sign in to comment.