Skip to content
Advertisement

Whats wrong with this regex to remove substring?

Trying to strip out the extra addressee from an address string. In the example below, dba bobs is the targeted string to remove.

JavaScript

The above yields:

JavaScript

When the desired is:

JavaScript

What am I doing wrong? Sometimes the input has a ‘n’ before the ‘dba’.

Advertisement

Answer

You can simplify your regex to: /b(attn|co|dba|fka|dept)b.*/gm

Test here: https://regex101.com/r/TOH9VV/2

JavaScript

EDIT: Included suggestion of user Cary Swoveland in the comments.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement